本文目錄一覽:
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/zh-hant/n/157686.html