share
Stack OverflowMSchart label inside chart area
[+3] [2] codery2k
[2012-07-30 08:00:02]
[ mschart ]
[ https://stackoverflow.com/questions/11717478/mschart-label-inside-chart-area ]

enter image description here

Can somebody please tell me how can i show the Total Collection on MSChart

I have got the answer in email which is incomplete , but i can't see it here, why ? help please. - codery2k
The mail you received is about an answer that has been deleted by owner (I can see it because I have more than 10K points). - digEmAll
[+4] [2012-08-05 08:13:56] digEmAll

You can use chart.Annotations [1] property to get a similar result.

For example with the following code (located after filling the chart):

var ann = new RectangleAnnotation();
ann.Text = "Total Collection" + Environment.NewLine + "250 Billion";
ann.IsMultiline = true;
ann.AxisX = this.chart1.ChartAreas[0].AxisX;
ann.AxisY = this.chart1.ChartAreas[0].AxisY;
ann.AnchorX = 9;  // as you can see from the image below,
ann.AnchorY = 41; // these values are inside the range

// add the annotation to the chart annotations list
this.chart1.Annotations.Add(ann);

I got the following result:

enter image description here

N.B.:
there are a lot of annotations types (CalloutAnnotation, EllipseAnnotation...) and they have a lot of properties to change styles and behaviors. You can even set a property to allow annotation moving (i.e. AllowMoving=true).

Have a look to annotation properties through intellisense or MSDN.

[1] http://msdn.microsoft.com/en-us/library/dd456725.aspx

@codery2k: did you add the annotation to the chart.Annotations collection ? (my updated code now show how...) Also, are you sure you have selected valid AnchorX and AnchorY values? (they must be in the visible range) - digEmAll
Yea I did it too, and I have selected valid X and Y axis, but still no result. :( - codery2k
1
[+1] [2013-06-26 17:41:52] Lucas

You can set the property IsDockedInsideChartArea to true. You will also need to specify which ChartArea the legend is docked to, and set the position property to Auto.

legend.IsDockedInsideChartArea = true;
legend.DockedToChartArea = "ChartArea1";

There are more information about this and other legend properties here [1].

[1] http://msdn.microsoft.com/en-CA/library/system.windows.forms.datavisualization.charting.legend.isdockedinsidechartarea.aspx

2