How to set chart type to pie

亡梦爱人 提交于 2019-12-05 05:47:19
zeFrenchy

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;
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!