gpt4 book ai didi

c# - 如何将图表类型设置为饼图

转载 作者:太空狗 更新时间:2023-10-29 19:59:58 25 4
gpt4 key购买 nike

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

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

最佳答案

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

我不确定我是否理解您尝试使用 HtmlNode 做什么,但下面的代码演示了如何使用 Dictionary 构建一个简单的饼图标签名称作为 Key,整数作为 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;
}

关于c# - 如何将图表类型设置为饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14181902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com