如何将图表类型设置为饼图 [英] How to set chart type to pie
问题描述
当我不放置图表类型就可以正常工作,但是当我将其设置为饼图时,它不能正常工作.它将所有系列名称都指定为Point 1,饼图只有1个蓝色块(一个圆圈),并且仅显示第一个点(值).
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++;
}
推荐答案
您要添加多个Series
,每个都有一个Point
.结果,图表控件仅显示第一个Series
.
我相信您要执行的操作是将多个点添加到单个Series
.
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
.
我不确定我是否理解您要使用HtmlNode
做什么,但是下面的代码演示了如何使用标签名作为Key和整数作为Value从Dictionary
构建简单的饼图.
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;
}
这篇关于如何将图表类型设置为饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!