this.chart.legend的簡單介紹

本文目錄一覽:

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

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-18 20:01
下一篇 2024-11-18 20:01

相關推薦

  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的“畫筆”在窗口中繪製…

    編程 2025-04-29
  • Python櫻花樹代碼簡單

    本文將對Python櫻花樹代碼進行詳細的闡述和講解,幫助讀者更好地理解該代碼的實現方法。 一、簡介 櫻花樹是一種圖形效果,它的實現方法比較簡單。Python中可以通過turtle這…

    編程 2025-04-28
  • Python大神作品:讓編程變得更加簡單

    Python作為一種高級的解釋性編程語言,一直被廣泛地運用於各個領域,從Web開發、遊戲開發到人工智能,Python都扮演着重要的角色。Python的代碼簡潔明了,易於閱讀和維護,…

    編程 2025-04-28
  • 用Python實現簡單爬蟲程序

    在當今時代,互聯網上的信息量是爆炸式增長的,其中很多信息可以被利用。對於數據分析、數據挖掘或者其他一些需要大量數據的任務,我們可以使用爬蟲技術從各個網站獲取需要的信息。而Pytho…

    編程 2025-04-28
  • 如何製作一個簡單的換裝遊戲

    本文將從以下幾個方面,為大家介紹如何製作一個簡單的換裝遊戲: 1. 遊戲需求和界面設計 2. 使用HTML、CSS和JavaScript開發遊戲 3. 實現遊戲的基本功能:拖拽交互…

    編程 2025-04-27
  • Guava Limiter——限流器的簡單易用

    本文將從多個維度對Guava Limiter進行詳細闡述,介紹其定義、使用方法、工作原理和案例應用等方面,並給出完整的代碼示例,希望能夠幫助讀者更好地了解和使用該庫。 一、定義 G…

    編程 2025-04-27
  • 2的32次方-1:一個看似簡單卻又複雜的數字

    對於計算機領域的人來說,2的32次方-1(也就是十進制下的4294967295)這個數字並不陌生。它經常被用來表示IPv4地址或者無符號32位整數的最大值。但實際上,這個數字卻包含…

    編程 2025-04-27
  • 製作一個簡單的管理系統的成本及實現

    想要製作一個簡單的管理系統,需要進行技術選型、開發、測試等過程,那麼這個過程會花費多少錢呢?我們將從多個方面來闡述製作一個簡單的管理系統的成本及實現。 一、技術選型 當我們開始思考…

    編程 2025-04-27

發表回復

登錄後才能評論