如何改变chart控件饼图的颜色

 我来答
就烦条0o
2017-02-22 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46492
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
series1.Points(0).Color = Color.Black
改一个小块颜色
chartField.Series.Clear();
chartField.ChartAreas.Clear();
chartField.Legends.Clear();
chartField.ChartAreas.Add(new ChartArea("Default"));
//设置图例背景色

Legend leg = new Legend();
leg.BackColor = Color.Transparent;
leg.Name = "Legend1";
chartField.Legends.Add(leg);
chartField.BackColor = Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(223)))), ((int)(((byte)(240)))));
chartField.BackGradientStyle = GradientStyle.TopBottom;
chartField.BackSecondaryColor = Color.White;

foreach (string key in chartLineDic.Keys)
{
Series serie = new Series();
serie.Name = key;
serie.LegendText = key;
serie.BorderWidth = 1;
serie.ChartType = SeriesChartType.Line;
serie.YValueType = ChartValueType.Int32;
serie.XValueType = ChartValueType.DateTime;
chartField.Series.Add(serie);
foreach (Temp t in chartLineDic[key])
{
chartField.Series[key].Points.AddXY(t.Date, t.Source);
}
chartField.Series[key].IsValueShownAsLabel = true;
chartField.Series[key].LabelAngle = 10;
}

this.chartEventPie.Series.Clear();
chartEventPie.ChartAreas.Clear();
chartEventPie.Legends.Clear();
chartEventPie.ChartAreas.Add(new ChartArea("Default"));
chartEventPie.ChartAreas["Default"].BackColor = chartEventPie.BackColor;
Legend legend = new Legend();
Series series = new Series();
legend.BackColor = chartEventPie.BackColor;
legend.IsEquallySpacedItems = true;
legend.IsTextAutoFit = false;
legend.Name = "Default";
this.chartEventPie.IsSoftShadows = false;

if (chartEventPieDic != null)
{
int index = 0;
foreach (string key in chartEventPieDic.Keys)
{
DataPoint dataPoint = new DataPoint(0, chartEventPieDic[key]);
dataPoint.CustomProperties = "OriginalPointIndex=" + index;
dataPoint.LegendText = key;
dataPoint.IsValueShownAsLabel = false;

if (key == "提示")
{

//设置饼图颜色
dataPoint.Color = Color.Blue;
}
if (key == "报警")
{
dataPoint.Color = Color.Red;
}
if (key == "正常")
{
dataPoint.Color = Color.Green;
}
if (key == "预警")
{
dataPoint.Color = Color.Yellow;
}
series.Points.Add(dataPoint);
index++;
}

this.chartEventPie.Legends.Add(legend);
series.ChartArea = "Default";
series.ChartType = SeriesChartType.Pie;
series.Label = "#PERCENT{P1}";
series.Legend = "Default";
series.XValueType = ChartValueType.Double;
series.YValueType = ChartValueType.Double;
this.chartEventPie.Series.Add(series);
chartEventPie.Series[0]["CollectedColor"] = "Gray";
}

图例显示位置

legend.Alignment = StringAlignment.Center;
legend.Docking = Docking.Bottom;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式