|
Labels on Line Chart |
Posted by JamieD on Dec-06-2010 10:54 |
|
Hello again Peter,
I'm implementing a modified sparkline idea using a multi-line chart to show different age groups. Rather than try to display the different groups using color I was going to also display a label to the right of each line. I've been using the point specific label assigned to the final point, as well as the idea of setPos, based of pushing the label outside of the chart itself into the white space on the right
set maleLabel = layermale.addCustomDataLabel(0, ubound(maleData),
call maleLabel.setPos(maleLabel.getLeftX()+50,maleLabel.getTopY())
What I've been stumped on is a manner to prevent when the lines all meet at the same end point, and if there would be a nice way to handle this sort of thing (similar to how the Pie Chart Labels can work to prevent collision but still be connected visually to their sectors). Perhaps I've taken things in a bit of a random direction, but it seems visually appealing! |
Re: Labels on Line Chart |
Posted by Peter Kwan on Dec-06-2010 17:28 |
|
Hi JamieD,
For your case, the text label can overlap if the points are the same or are "close enough". There is no automatic means to avoid the text boxes from overlapping in your case. You may consider to develop your own method to position the text boxes.
If I were you, I may try the following methods:
(a) After adding and configuring the line layers, call "BaseChart.layout" to auto-scale the axis. Thereafter, you can use XYChart.getYCoor to get the position of the data points.
(b) Add text boxes (using addText) to the right side of the chart at the position of the data points. You may get the heights of the text boxes after creating them. (They may or may not be of the same height. It depends on what you put into the text boxes.)
(c) Using the positions and heights, you may find that some text boxes overlaps. You would need to come up with an algorithm to slide the text boxes up and down so that they do not overlap. After sliding the boxes, you may optionally use a join line to join the boxes with the data point.
Hope this can help.
Regards
Peter Kwan |
|