Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSchart label inside chart area

Tags:

mschart

enter image description here

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

like image 788
codery2k Avatar asked May 10 '26 19:05

codery2k


2 Answers

You can use chart.Annotations 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.

like image 186
digEmAll Avatar answered May 13 '26 08:05

digEmAll


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.

like image 23
Lucas Avatar answered May 13 '26 10:05

Lucas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!