ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-05-2011 15:15
Attachments:
请参照下面的图,比如Test Value(Limit 4-13.5),即算出在x轴的一个点为 8.7 计算方式:[(4+13.5)/2]
此时,想要Y轴与此点交汇,即把(8.7,0)作为交汇的原点,请问这个怎么实现?实现后的效果图为第二张.
dis.JPG
dis_after.JPG

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Peter Kwan on Jun-06-2011 09:58
Hi Cherry,

You may use XYChart.addAxis to add an axis at any position you like. For example, in Java:

//add axis to the left side, shift 200 pixels internal to the plot area
Axis a = c.addAxis(Chart.Left, -200);

//synchroinze the axis scale with the main y-axis
a.syncAxis(c.yAxis());

//hide the main y-axis
c.yAxis().setColors(Chart.Transparent, Chart.Transparent);

For your case, you would need to compute where to add the axis. It depends on how your x-axis is configured. Assuming you are using a label based x-axis (configured using Axis.setLabels2), the x-coordinate to be computed like:

double desiredPos = 8.7;
double xCoor = ((desiredPos - myXData[0]) / (myXData[data.length - 1] - myXData[0]) * (data.length - 1) + 0.5) / data.length * c.getPlotArea().getWidth();

Axis a = c.addAxis(Chart.Left, -xCoor);
a.syncAxis(c.yAxis());
c.yAxis().setColors(Chart.Transparent, Chart.Transparent);

Hope this can help.

Regards
Peter Kwan

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-06-2011 10:41
Hi Peter Kwan,

Thank you so much! I really appreciate your help.

Thanks,

Cherry

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-07-2011 11:18
Hi Peter Kwan,

I try it by above step,I used a label based x-axis (configured using Axis.setLabels), so the result of  "xCoor " is not accurate, why ?


Thanks,

Cherry

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Peter Kwan on Jun-07-2011 23:57
Hi Cherry,

To diagnose the problem, please comment out your existing x-axis title code, and replace it with the following code:

c.xAxis().addTitle("" + xCoor + "," + desiredPos + "," + myXData[data.length - 1] + "," + myXData[0] + "," + data.length + "," + c.getPlotArea().getWidth());

Now we should be able to see the parameters on the chart in the x-axis title. Please kindly attached the chart image for analysis.

Hope this can help.

Regards
Peter Kwan

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-22-2011 23:40
Hi Hi Peter Kwan,

I want to insert a line at point(8.7,0),but this line parallel with Y axis.How can do this ?

Thanks,

Cherry

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Peter Kwan on Jun-23-2011 05:49
Hi Cherry,

After looking at your chart in your earlier message carefully, I realize your chart is in 3D. There is a "depth" in the plot area. The bars are plotted at tha back of the plot area, while the axis is plotted at the front of the plot area. (In ChartDirector, because of the 3D projection method, the left y-axis and bottom x-axis is in front of the plot area, while the right y-axis is at the back.) There is probably an invisible layer (eg. with no data) in your code that creates the 3D effect. The 3D effect causes the bars at the back appear to offset by a few pixels horizontal and vertically relative to the axes in front.

If the 3D effect is not what you want, you may consider to remove that layer.

For inserting a vertical line at x = 8.7, you may use addMark. As your chart is in 3D, you may add the line in front of the plot area, or at the back. To add it in front, use:

c.xAxis().addMark(8.7, 0x000000);

To add it at the back, use:

c.xAxis().addMark(8.7, 0x000000).setDrawOnTop(false);

Hope this can help.

Regards
Peter Kwan

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-23-2011 09:53
Hi Peter Kwan,

I used your method,but the result is wrong.For example,

X axis:10 ,12, 14,16,18,20,I want to insert line at point(14,0).But used above method(c.xAxis().addMark(14, 0x000000)),the line disappeared.If i used c.xAxis().addMark(3, 0x000000),the result is true,Why ?


Thanks,
Cherry

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Peter Kwan on Jun-24-2011 04:32
Hi Cherry,

This means you are using a label based x-axis (set up using Axis.setLabels or Axis.setLabels2).

In a label based x-axis, the labels has no meaning and is for human reading only. For example, the x-axis labels may be names like {"Apple", "Orange", "Pears", "222", "10/12/2011", "Pears"}. Of course, you can also use the labels {"10", "12", .... "20"} if you like.

For a label based x-axis, the x-coordinate is the array index of the label. For example, for the labels {"Apple", "Orange", "Pears", "222", "10/12/2011", "Pears"}, the x-coordinate for the first "Pears" label is x = 2, and the x-coordinate for the second "Pears" label is 5. The x-coordinate for the position in between the first "Pears" and "222" is x = 2.5.

For your case {10 ,12, 14, 16, 18, 20}, the 14 is the third label, so it should be at x = 2. (If it is at x = 3, then there may be another label before 10. Note that even an empty string is a label.)

In brief, for label based x-axis, you should specify the index position of the labels array, not the labels themselves. You may use fractional numbers for a position in between 2 labels.

Hope this can help.

Regards
Peter Kwan

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-26-2011 20:07
Hi Peter Kwan,

Above summary,In my case,the x-axis lables are dynamic and x-axis value is from database.
At the same time i calculate middle of x-axis(midle=(upperlimit+lowerlimit)/2),so I want insert a line at this point.I used addMark,but this method about index position ,not the fact value,I think whether some formula about this ?For example,you used below method calculate y-axis position:

double desiredPos = 8.7;
double xCoor = ((desiredPos - myXData[0]) / (myXData[data.length - 1] - myXData[0]) * (data.length - 1) + 0.5) / data.length * c.getPlotArea().getWidth();

Axis a = c.addAxis(Chart.Left, -xCoor);
a.syncAxis(c.yAxis());

so ,Do you have similar method about this case ?



Thanks,

Cherry

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Peter Kwan on Jun-27-2011 02:55
Hi Cherry,

The xIndex is the first part of the formula to compute the xCoor. It is:

double xIndex = (desiredPos - myXData[0]) / (myXData[data.length - 1] - myXData[0]) * (data.length - 1);

Hope this can help.

Regards
Peter Kwan

  Re: XYChart的原点设置到任意位置(针对轴)
Posted by Cherry on Jun-27-2011 16:59
Hi Peter Kwan,

Thank you so much.

Cherry

Thansks.