Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the view angle and label value of a chart .NET C#

Short Description

I am using charts for a specific application where i need to change the view angle of the rendered 3D Pie chart and value of automatic labels from pie label names to corresponding pie values.

This how the chart looks: Pie Chart


Initialization

This is how i initialize it:

    Dictionary<string, decimal> secondPersonsWithValues = HistoryModel.getSecondPersonWithValues();
    decimal[] yValues = new decimal[secondPersonsWithValues.Values.Count]; //VALUES
    string[] xValues = new string[secondPersonsWithValues.Keys.Count]; //LABELS
    secondPersonsWithValues.Keys.CopyTo(xValues, 0);
    secondPersonsWithValues.Values.CopyTo(yValues, 0);
    incomeExpenseChart.Series["Default"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
    incomeExpenseChart.Series["Default"].Points.DataBindXY(xValues, yValues);
    incomeExpenseChart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
    incomeExpenseChart.Series["Default"].CustomProperties = "PieLabelStyle=Outside";
    incomeExpenseChart.Legends["Default"].Enabled = true;
    incomeExpenseChart.ChartAreas["Default"].Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
    incomeExpenseChart.Series["Default"]["PieDrawingStyle"] = "SoftEdge";

Basically i am querying data from database using the HistoryModel.getSecondPersonWithValues(); to get pairs as Dictionary<string, decimal> where key is the person and value is ammount.


Problem #1

What i need is to be able to change the marked labels from person names to the ammounts or add another label of ammounts with the same colors (See Image). enter image description here


Problem #2

Another problem is that i need to change the view angle of 3D Pie chart. Maybe it's very simple and I just don't know the needed property or maybe i need to override some paint event. Either ways any kind of ways would be appriciated.

Thanks in advance George.

like image 231
George Avatar asked Feb 22 '11 15:02

George


People also ask

How do I change the label options to display Percent format first?

To format data labels, select your chart, and then in the Chart Design tab, click Add Chart Element > Data Labels > More Data Label Options. Click Label Options and under Label Contains, pick the options you want.

How do you label a pie chart in Excel?

Add data labelsClick the chart, and then click the Chart Design tab. Click Add Chart Element and select Data Labels, and then select a location for the data label option. Note: The options will differ depending on your chart type.

How do you add data labels in Powerpoint?

On the Layout tab, in the Labels group, click Data Labels, and then click the option that you want. For additional data label options, click More Data Label Options, click Label Options if it's not selected, and then select the options that you want.


1 Answers

Solution for Problem #1

Adding new Label and filling with custom values helped. In addition i changed the Series.IsValueShownAsLabel = true;


Solution for Problem #2

I should have set the ChartArea.Area3DStyle.IsClustered = true; and then set the ChartArea.Area3DStyle.Inclination;

like image 111
George Avatar answered Sep 19 '22 06:09

George