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

Message ListMessage List     Post MessagePost Message

  Uneven Y axis lables.
Posted by Ankit Jain on Jan-09-2018 12:18
Attachments:
Hi Peter,

I am implementing bar chart with uneven y axis labels.

For e.g. my y axis label will look like(-100,-10,0,10,100,300,800).I can change the labels but the bar heights are not getting auto adjusted.

for e.g. I am having data points as 10,100,250,800 but these are not in sync with y axis label. I have gone through few older post but could not find solution to my problem.

Attached is sample bar chart getting generated with current code.

Thanks
Ankit
Bar_Chart.jpg
Bar_Chart.jpg

17.89 Kb

  Re: Uneven Y axis lables.
Posted by Peter Kwan on Jan-10-2018 18:34
Hi Ankit,

In ChartDirector, the y-data value is used to position the data elements, such as to determine the length of the bar in a bar chart. For example, the length of a bar at with value = 800 should be 8 times the length of a bar with value = 100 (assuming the baseline of the bar is at y = 0).

On the other hand, the y-axis label can be anything. It is only for human reading. For example, you can use the text "high", "medium", "low" for the y-axis labels. Of course, you would need to tell ChartDirector where are the "high", "medium" and "low" labels. For most charts, people just use the y-data value as the y-axis labels, which means the "800" label is simply position at y = 800.

You can certainly use -100, 10, 0, 10, 100, 300, 800 for the y-axis labels. I assume you would like to label "800" to be located at y = 800. In this case, the code is like:

c.yAxis().setLinearScale(-100, 800, Chart.NoValue);

double[] allLabels = {-100,-10,0,10,100,300,800};
for (int i = 0; i < allLabels.Length; ++i)
   c.yAxis().addLabel(allLabels[i], "" + allLabels[i]);

Hope this can help.

Regards
Peter Kwan

  Re: Uneven Y axis lables.
Posted by Ankit Jain on Jan-10-2018 22:38
Attachments:
Hi Peter,

Thanks for your reply. But my requirement is different. Hope this time I will be able to put my requirement in more clear way.

I have labels to put like {0,10,100,400,500} spaced equally. This is I achieved.
Next task is to make the bar heights as per the labels.

For e.g. when I have to draw a bar of 10 it will actually be till 100.
In attached image I have data points 10,100,250 and 500 to draw but what I require is bar width to reach till black color mark I put on image.

Always appreciate your suggestions and quick replies.

Thanks
Ankit
Bar.jpg
Bar.jpg

16.36 Kb

  Re: Uneven Y axis lables.
Posted by Peter Kwan on Jan-11-2018 02:18
Hi Ankit,

In your case, the 0, 10, 100, 400, 500 can be only considered as "names" in ChartDirector, as they cannot be used to determine the bar length. (For example, what is the exactly length if the bar is 210?) To achieve what you need, you may just set the y-axis scale to be 0 to 4 (the array index of the labels). For example:

String[] labels = { "0", "10", "100", "400", "500" };
c.yAxis().setLinearScale(0, labels.Length - 1, labels);

Then for the bar values, you can use the data value 0, 1, 2, 3, 4 to represent the five label positions. In other words, you use the array index of the labels as the bar value. If you need to have a bar length somewhere between the labels, you can use a non-integer for the bar value (eg. 1.5 to mean the middle of 10 and 100).

Hope this can help.

Regards
Peter Kwan

  Re: Uneven Y axis lables.
Posted by Ankit Jain on Jan-15-2018 15:38
Thanks Peter for your help!