I am creating a point line graph with 4 horizontal lines. Across the bottom are years whose minimum is 1 and whose maximum value varies from 5 to 12. I am graphing vertically dollar amounts whose magnitude varies. I have successully figured out everything EXCEPT adding 4 rows of annotations across the graph echoing the exact yvalue in the same color as the line. When I use a series paint listener and try series painted calc x pos method returns the values I'm looking for but the annotations do not show up on my graph. If I use series painting or myChart.refreshControl (saw in an example) without a listener they come back zero and all of my annotations print way to the left and on top of each other.
I am trying to mimic what was done in a VB application by calculating the top and left positions of teh annotations
Here is the code at the bottom of my routine (sorry for the formatting)
myChart.refreshControl();
// myChart.getSeries(0).addSeriesPaintListener( new SeriesPaintAdapter() {
// public void seriesPainted(ChartDrawEvent e) { int seriesCount = myChart.getSeriesCount(); int toolsmax = 0;
for (int iseries = 0; iseries < seriesCount;iseries++) {
toolsmax += myChart.getSeries(iseries).getCount(); }
Annotation[] tools = new Annotation[toolsmax];
int itool = 0;
for (int iseries = 0; iseries < seriesCount;iseries++) {
int count = myChart.getSeries(iseries).getCount();
ValueList values = myChart.getSeries(iseries).getYValues();
for (int i = 0; i < count;i++) { int xval = myChart.getSeries(iseries).calcXPos(i);
double value = values.getValue(i);
tools[itool]= new Annotation(myChart.getChart());
myChart.getChart().getTools().add(tools[itool]);
tools[itool].setText(Format.formatNumber(value,"#,##0"));
tools[itool].getShape().setTransparent(true);
tools[itool].getShape().setCustomPosition(true);
tools[itool].getShape().getFont().setSize(7);
tools[itool].getShape().getFont().setColor(lineColor[iseries]);
int leftMargin = xval; if (i == 0) {
leftMargin -= 6;} else if (count == 12) { leftMargin -= (i*4); }
else if (count == 10) {
leftMargin -= (i*5); }
else if (count == 9) {
leftMargin -= (i*6); }
else if (count == 8) {
leftMargin -= i*7); }
else if (count == 7){
leftMargin -= (i*8); }
else if (count == 6){
leftMargin -= (i*9); }
else if (count == 5){
leftMargin -= (i*10); }
tools[itool].setLeft(leftMargin);
tools[itool].setTop(lineOffset[iseries]);
itool+=1;
}}
// }
// });
try
{
myChart.getExport().getImage().getJPEG().save(jpgFileName);
}
Problems with retrieving xy coordinates for annotation
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi cathy,
You should use the chart paint listener for having valid positions and setting annotations custom position there. You'll find more information about that at Tutorial 10 - Custom drawing on the Chart Panel included with TeeChart's installation.
Another custom drawing example can be found here.
If this doesn't help please send us a code snippet we can run "as-is" to reproduce the problem here.
Thanks in advance.
You should use the chart paint listener for having valid positions and setting annotations custom position there. You'll find more information about that at Tutorial 10 - Custom drawing on the Chart Panel included with TeeChart's installation.
Another custom drawing example can be found here.
If this doesn't help please send us a code snippet we can run "as-is" to reproduce the problem here.
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |