本文目录一览:
Extjs 4.2 chart中如何自定义legend 图列
重写下面这个方法:
Ext.chart.LegendItem.prototype.getLabelText = function() {
var me = this, series = me.series, idx = me.yFieldIndex;
function getSeriesProp(name) {
var val = series[name];
return (Ext.isArray(val) ? val[idx] : val);
}
return getSeriesProp(‘dispalyField’) || getSeriesProp(‘yField’);
};
然后在series配置中添加如下
yField : [‘dataSum’, ‘dataSuccSum’, ‘dataFailSum’],
dispalyField : [‘总数’,
‘成功’,
‘失败’]
yField 是原生属性,dispalyField 是扩展属性.里面配置你想要显示的数据.注意要和yField 对应
有关C#中chart属性的设置
把你表中的字段绑定到x轴和Y轴,有数据的话,应该会自动显示出不同的颜色。
比如:
chart1.Series[“Series1”].Points.DataBindXY(tempReader, “月份”, tempReader, “平均合格率”);
chart1.Series[“Series1”].LegendText = strname;
下面是创建饼图的代码,不知对你有没有帮助:
Series seriesPies = new Series(subjectName+”按行政区划分布图”);
this.ChartPie.Series.Add(seriesPies);
this.ChartPie.ChartAreas[0].Area3DStyle.Enable3D = true;
seriesPies.ChartType = SeriesChartType.Pie;
seriesPies.BorderWidth = 3;
seriesPies.ShadowOffset = 2;
seriesPies.Label = ” “; // “#PERCENT{P}”;
seriesPies.LegendText = “#VALX”;
Title tPie = new Title(subjectName + “按行政区划分布图”, Docking.Top, new Font(FontFamily.GenericSerif, 15, FontStyle.Bold), Color.Black);
tPie.ShadowColor = Color.Gray;
tPie.ShadowOffset = 0;
this.ChartPie.Titles.Add(tPie);
this.ChartPie.Series[subjectName + “按行政区划分布图”].ToolTip = “#VALX: #PERCENT{P}”;
this.ChartPie.Series[subjectName + “按行政区划分布图”].Label = “#PERCENT{P}”;
for (int i = 0; i dt.Rows.Count; i++)
{
object count = dt.Rows[i][“count”];
//seriesPies.CustomProperties = “PieLabelStyle=OutSide”; //让饼状图的图示区域和图示文本用线连接
seriesPies.Points.AddXY(string.Concat(dt.Rows[i][“xzqh”], “(“, count, “)”), count);
}
如何改变chart控件饼图的颜色
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;
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/157686.html