【问题标题】:How to set chart type to pie如何将图表类型设置为饼图
【发布时间】:2013-01-06 12:05:45
【问题描述】:

当我在没有放置图表类型的情况下执行此操作时工作正常,但当我将其设置为饼图时,它无法正常工作。它将所有系列名称作为点 1,馅饼只有 1 个蓝色块(一个圆圈),它只显示第一个点(值)。

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++;
}

【问题讨论】:

    标签: c# mschart pie-chart


    【解决方案1】:

    您正在添加多个Series,每个Point。因此,图表控件仅显示第一个 Series。 我相信您想要做的是将多个点添加到单个 Series

    我不确定我是否理解您要使用HtmlNode 做什么,但下面的代码演示了如何使用标记名称作为键和整数作为值从Dictionary 构建一个简单的饼图。

            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;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多