Drawing colorLines with annotations (or any type of label)?
Posted: Thu Mar 26, 2009 9:38 pm
I use a colorLine to mark a point on the bottom axis. I need to add a label near the chart that corresponds to this colorLine. For this, I use an Annotation and set a custom position which I obtain using:
annotationSeg1.Left = Convert.ToInt16(tChart.Axes.Bottom.CalcPosValue(segTimeSum));
When the chart is zoomed, the colorLines move automatically (as they should). The problem is that the Annotations do not move.
To resolve this, I added code to the tChart_Zoomed() event which does the following:
Bitmap b = tChart.Bitmap; // force the chart to redraw so CalcPosValue will calc the proper value
annotationSeg1.Left = 3 + Convert.ToInt16(tChart.Axes.Bottom.CalcPosValue(segTimeSum));
This all works 'fine' (its a little bulky because I actually have to cycle through a foreach statement to update up to 16 annoatationSeg's).
Basically, I need to draw a vertical line on a graph to mark a position and I need to label this random line (within the graph right near the line) so the user knows what it is.
1. Is there a better way to draw a line (with a label) at a given x-axis coordinate?
2. If not, is there a way to snap an Annotation to a colorLine so they move together?
Thanks,
Kevin
annotationSeg1.Left = Convert.ToInt16(tChart.Axes.Bottom.CalcPosValue(segTimeSum));
When the chart is zoomed, the colorLines move automatically (as they should). The problem is that the Annotations do not move.
To resolve this, I added code to the tChart_Zoomed() event which does the following:
Bitmap b = tChart.Bitmap; // force the chart to redraw so CalcPosValue will calc the proper value
annotationSeg1.Left = 3 + Convert.ToInt16(tChart.Axes.Bottom.CalcPosValue(segTimeSum));
This all works 'fine' (its a little bulky because I actually have to cycle through a foreach statement to update up to 16 annoatationSeg's).
Basically, I need to draw a vertical line on a graph to mark a position and I need to label this random line (within the graph right near the line) so the user knows what it is.
1. Is there a better way to draw a line (with a label) at a given x-axis coordinate?
2. If not, is there a way to snap an Annotation to a colorLine so they move together?
Thanks,
Kevin