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

Message ListMessage List     Post MessagePost Message

  setLabels
Posted by Emilio on Jan-20-2017 22:10
Attachments:
Hi,

Our validation of the your product is proceeding nicely. However I've run into some trouble with assigning String based labels to the y axis.

The attached images are charts that indicate a vehicles gear changes.

without setting labels.PNG - shows the axis without setting labels

setLabels_outcome.PNG  - details what happens when I use
chart.yAxis().setLabels(dbt.getColAsString(4));

It seems to writing out every label.

setLinearScale2_outcome.PNG - details the outcome of the following code
chart.yAxis().setLinearScale2(minVal, maxVal, labels)

The data set here matches the unique values of the charted dataset. But it mislabels the points.

What would be the best way to add labels to the axis. I would also like to add labels for values that do not exist in a dataset. An example here 10 represents 1st gear, 20 to second gear, 30 to 3rd gear. A person may go from 1st straight to 3rd gear but I'd like the 2nd gear label to show.

Please help.

Warm Regards
without setting labels.PNG
setLabels_outcome.PNG
setLinearScale2_outcome.PNG

  Re: setLabels
Posted by Peter Kwan on Jan-21-2017 03:48
Hi Emilio,

In ChartDirector, labels are treated as "names". They are just displayed in the chart as is and have no other meaning to ChartDirector. For example, "Apple", "Mars", "13", "1-1-2017", "ABC" are all labels.

To add labels to the y-axis, if you only provide the labels but not their positions, ChartDirector will automatically position the labels.

If you use:

chart.yAxis().setLinearScale2(minVal, maxVal, labels)

then the labels will be spread evenly between minVal and maxVal. For example, if minVal is 0, and maxVal is 10, and you have 3 labels "Apple", "13", "Eight", the "Apple" will be position at y = 0, the "13" will be position at y = 5 and the "Eight" will be at y = 10.

If you use:

chart.yAxis().setLabels(labels)

because there is no y-axis scale provided, the labels will simply be assumed to be at y = 0, 1, 2, .... So for the above example, "Apple" will be at y = 0, "13" will be at y = 1 and "Eight" will be at y = 2. The y-axis scale will also be set to be 0 to 2.

For your case, if you need to put custom labels at custom positions, one method is:

// y-axis scale from minVal to maxVal with no label
chart.yAxis().setLinearScale2(minVal, maxVal, null);

chart.yAxis().addLabel(10, "1st gear");
chart.yAxis().addLabel(20, "2nd gear");
chart.yAxis().addLabel(30, "3rd gear");

The y-axis range should include the data range, but the y-axis labels are not related to the data values. For example, suppose your data values are 1.147, 3.18247, 9.013, If the axis is auto-scaled by ChartDirector, ChartDirector may choose 0 to 10 as the axis range, and the labels can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. Note the axis labels are not equal to any data value, but the axis range 0 to 10 includes the data range 1.147 to 9.013.

If you prefer to let ChartDirector automatically determine the axis range (so that you do not need to specific the minValue and maxValue), but you would like to use custom labels, one method is:

//If you do not special the axis scale, the axis will be auto-scaled

// Set the auto-scaled labels to transparent, so there is no visible label
chart.yAxis().setLabelStyle("Arial", 8, Chart.Transparent);

// Add a custom label as mark lines
chart.yAxis().addMark(10, -1, "1st gear", "Arial", 8).setMarkColors(0xdddddd, 0x000000);
.... add other labels as needed ....

Hope this can help.

Regards
Peter Kwan

  Re: setLabels
Posted by Emilio on Jan-23-2017 23:45
Perfect. Redistribution License purchased today :)

This worked:

chart.yAxis().setLinearScale2(minVal, maxVal, null);

I then loop and add items:
chart.yAxis().addLabel(10, "1st gear");

-------

The chart also uses the Trackline with Legend feature. How do I get the legend to display the labels instead of the number values?

Many Thanks