Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set chart type to pie

When I do it without putting chart type is working fine but when I set it to pie its not working correct. It put all series name as Point 1 the pie is only 1 blue piece (one circle) and it show only first point (Value).

foreach (var tag in tags)
{
    HtmlNode tagname = tag.SelectSingleNode("a");
    HtmlNode tagcount = tag.SelectSingleNode("span/span");
    chart1.Series.Add(tagname.InnerText);
    chart1.Series[x].Points.AddY(int.Parse(tagcount.InnerText));
    chart1.Series[x].IsValueShownAsLabel = true;
    chart1.Series[x].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
    x++;
}
like image 987
a1204773 Avatar asked Jan 06 '13 12:01

a1204773


People also ask

How do I change the default chart type in Excel?

On the Design tab, click Change Chart Type. Select a chart type that you'd prefer being the default, but don't click OK just yet. Look at the top of the All Charts tab, and find the chart icon that's highlighted in gray. Right-click the chart icon that's highlighted in gray, and click Set as Default Chart.


1 Answers

You are adding multiple Series, each with one Point. As a result the charting control only displays the first Series. I believe what you are wanting to do is adding multiple points to a single Series.

I'm not sure I understand what you are trying to do with the HtmlNode but the code below demonstrate how to build a simple pie chart from a Dictionary using a tag name as Key and an integer as Value.

        Dictionary<string, int> tags = new Dictionary<string,int>() { 
            { "test", 10 },
            { "my", 3 },
            { "code", 8 }
        };

        chart1.Series[0].Points.Clear();
        chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
        foreach (string tagname in tags.Keys)
        {
            chart1.Series[0].Points.AddXY(tagname, tags[tagname]);
            //chart1.Series[0].IsValueShownAsLabel = true;
        }
like image 57
zeFrenchy Avatar answered Nov 08 '22 07:11

zeFrenchy