Is there a way using a WinChart to click on a chart element and add a label to it? For instance, I have a Scatter Chart and I want drop a label down next to the point when it is clicked on. I know there is an event that I can handle and it gives me the row and column from my datatable that this point is from. I can get the name I want to display and add it as a tooltip, but I want a static label to appear.
perhaps a CalloutAnnotation would suit this purpose better? it is designed to have an anchor point and an offset point.
otherwise, using calculations like that for ValueX and ValueY is tricky because it's based on how the corresponding Axis would map that data value. if it's an ordinal axis (like the x-axis in a column chart), you could try adding or subtracting .5, but any calculations beyond that will be problematic.
if you need more control over the positioning, you could handle the FillSceneGraph event to add custom Box & Text primitives to the SceneGraph.
Thanks. That helped. Now that I can add annotations, how can I add annotations at a specific X,Y location when I click on a point in my ScatterChart. I am handling the "ChartDataClicked" event, and I can get the DataRow from the ChartDataEventArgs parameter.
From that row, I can get the values of the data and set the Location.ValueX and ValueY
ann.Location.Type = LocationType.DataValues
ann.Text = Convert.ToString(row(0))
ann.Height = 10
ann.Width = ann.Text.Length * 7
ann.Visible = True
ann.Location.ValueX = Convert.ToDouble(row(1))
ann.Location.ValueY = Convert.ToDouble(row(2))
myChart.Annotations.Add(ann)
This works, but it puts the annotation on top of the point. I am trying to find a way to offset it to start at the same X location as the point, but be offset below. I thought I could just use the X location and then subtract the height of the annotation for Y
(i.e. ann.Location.ValueY = Convert.ToDouble(row(2)) - ann.Height ).
The problem is that the annotation always seems to be centered on the point as opposed to having its "Left" at the value of the X.
Sure, just check the WinChart samples. There are Annotations samples in there.
check the documentation as well: http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR2.0/html/Chart_Annotations.html
Is there an example on how to add Annotations to the chart ?
try adding a ChartTextAppearance object to the ScatterChart.ChartText collection.
or, add an Annotation to the chart's Annotations collection.