最近公司項目要用到Chart圖表控件,這是一個比較老的東西了,目前網絡上似乎已經不太流行這個控件,但是只要配置了相關的屬性,效果還是可以的。前前后后摸索了好久,接下來談談這個件控件最重要的幾個屬性。
1.ChartAreas屬性
ChartAreas屬性指繪圖區,一個控件可以有多個繪圖區,比如我要在同一個控件內顯示餅圖和柱狀圖,肯定不能放在同一個ChartAreas區域內,應該在同一個Chart控件里增加兩個ChartAreas並分別綁定Series對象。所以ChartAreas屬性對應的是一個集合。
2.Series屬性
Series屬性就是各種圖表的圖形啦,比如我們要顯示某月的天氣變化,那么應該有這樣兩組數據,一組是天數,一組是每天對應的溫度值,同時綁定到Series對象中,再將Series對象Add()到Chart控件的Series屬性里即可。為了橫向比較,例如我要看本月與上月的天氣曲線變化圖,並同時顯示在同一個ChartAreas中,那該怎么辦呢?很簡單,再實例一個Series對象,將上月的天數數組與溫度值數組綁定到一個新的Series2實例中,再將Series2實例Add()到Chart控件的Series屬性里,此時,Chart控件的第一個繪圖區ChartArea里就會有兩條曲線。
3.Legends屬性
Legend就是指一個圖標的圖例,當一個Series屬性有多個Series時,或是一個Series有幾組數據時,為了區分各自的顏色,通常每個Serie對象一種顏色,這就需要用到圖例來指明哪個顏色的代表的是什么數據。如下圖所示:




4.關於數據的綁定
將要顯示的X軸和Y軸的數據分別放到兩個數組里在, 然后綁定即可。
cht1.Series[0].Points.DataBindXY(x, y);
完整的代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] x = new string[] { "南山大隊", "福田大隊", "羅湖大隊", "寶安大隊", "指揮處", "大帝科技", "南山大隊", "福田大隊", "羅湖大隊", "寶安大隊", "指揮處", "大帝科技"};
double[] y = new double[] { 541, 574, 345, 854, 684, 257, 541, 574, 345, 854, 684, 257 };
string[] z = new string[] { "", "", "", "", "", "", "", "", "", "", "", "" };
string[] a = new string[] { "南山大隊", "福田大隊", "羅湖大隊", "寶安大隊", "指揮處", };
double[] b = new double[] { 541, 574, 345, 854, 257 };
#region 柱狀圖
//標題
cht1.Titles.Add("柱狀圖數據分析");
cht1.Titles[0].ForeColor = Color.White;
cht1.Titles[0].Font = new Font("微軟雅黑", 12f, FontStyle.Regular);
cht1.Titles[0].Alignment = ContentAlignment.TopCenter;
cht1.Titles.Add("合計:25414 宗");
cht1.Titles[1].ForeColor = Color.White;
cht1.Titles[1].Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
cht1.Titles[1].Alignment = ContentAlignment.TopRight;
//控件背景
cht1.BackColor = Color.Transparent;
//圖表區背景
cht1.ChartAreas[0].BackColor = Color.Transparent;
cht1.ChartAreas[0].BorderColor = Color.Transparent;
//X軸標簽間距
cht1.ChartAreas[0].AxisX.Interval = 1;
cht1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht1.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht1.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 14f, FontStyle.Regular);
cht1.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//X坐標軸顏色
cht1.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
cht1.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//X坐標軸標題
//cht1.ChartAreas[0].AxisX.Title = "數量(宗)";
//cht1.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
//cht1.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//cht1.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;
//cht1.ChartAreas[0].AxisX.ToolTip = "數量(宗)";
//X軸網絡線條
cht1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht1.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//Y坐標軸顏色
cht1.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
cht1.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//Y坐標軸標題
cht1.ChartAreas[0].AxisY.Title = "數量(宗)";
cht1.ChartAreas[0].AxisY.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
cht1.ChartAreas[0].AxisY.TitleForeColor = Color.White;
cht1.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Rotated270;
cht1.ChartAreas[0].AxisY.ToolTip = "數量(宗)";
//Y軸網格線條
cht1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht1.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht1.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht1.ChartAreas[0].BackGradientStyle = GradientStyle.TopBottom;
Legend legend = new Legend("legend");
legend.Title = "legendTitle";
cht1.Series[0].XValueType = ChartValueType.String; //設置X軸上的值類型
cht1.Series[0].Label = "#VAL"; //設置顯示X Y的值
cht1.Series[0].LabelForeColor = Color.White;
cht1.Series[0].ToolTip = "#VALX:#VAL"; //鼠標移動到對應點顯示數值
cht1.Series[0].ChartType = SeriesChartType.Column; //圖類型(折線)
cht1.Series[0].Color = Color.Lime;
cht1.Series[0].LegendText = legend.Name;
cht1.Series[0].IsValueShownAsLabel = true;
cht1.Series[0].LabelForeColor = Color.White;
cht1.Series[0].CustomProperties = "DrawingStyle = Cylinder";
cht1.Legends.Add(legend);
cht1.Legends[0].Position.Auto = false;
//綁定數據
cht1.Series[0].Points.DataBindXY(x, y);
cht1.Series[0].Points[0].Color = Color.White;
cht1.Series[0].Palette = ChartColorPalette.Bright;
#endregion
#region 餅圖
//標題
cht2.Titles.Add("餅圖數據分析");
cht2.Titles[0].ForeColor = Color.White;
cht2.Titles[0].Font = new Font("微軟雅黑", 12f, FontStyle.Regular);
cht2.Titles[0].Alignment = ContentAlignment.TopCenter;
cht2.Titles.Add("合計:25412 宗");
cht2.Titles[1].ForeColor = Color.White;
cht2.Titles[1].Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
cht2.Titles[1].Alignment = ContentAlignment.TopRight;
//控件背景
cht2.BackColor = Color.Transparent;
//圖表區背景
cht2.ChartAreas[0].BackColor = Color.Transparent;
cht2.ChartAreas[0].BorderColor = Color.Transparent;
//X軸標簽間距
cht2.ChartAreas[0].AxisX.Interval = 1;
cht2.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht2.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht2.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 14f, FontStyle.Regular);
cht2.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//X坐標軸顏色
cht2.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht2.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
cht2.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//X坐標軸標題
cht2.ChartAreas[0].AxisX.Title = "數量(宗)";
cht2.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
cht2.ChartAreas[0].AxisX.TitleForeColor = Color.White;
cht2.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Horizontal;
cht2.ChartAreas[0].AxisX.ToolTip = "數量(宗)";
//X軸網絡線條
cht2.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht2.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//Y坐標軸顏色
cht2.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht2.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
cht2.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//Y坐標軸標題
cht2.ChartAreas[0].AxisY.Title = "數量(宗)";
cht2.ChartAreas[0].AxisY.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
cht2.ChartAreas[0].AxisY.TitleForeColor = Color.White;
cht2.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Rotated270;
cht2.ChartAreas[0].AxisY.ToolTip = "數量(宗)";
//Y軸網格線條
cht2.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht2.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht2.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
//背景漸變
cht2.ChartAreas[0].BackGradientStyle = GradientStyle.None;
//圖例樣式
Legend legend2 = new Legend("#VALX");
legend2.Title = "圖例";
legend2.TitleBackColor = Color.Transparent;
legend2.BackColor = Color.Transparent;
legend2.TitleForeColor = Color.White;
legend2.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
legend2.Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
legend2.ForeColor = Color.White;
cht2.Series[0].XValueType = ChartValueType.String; //設置X軸上的值類型
cht2.Series[0].Label = "#VAL"; //設置顯示X Y的值
cht2.Series[0].LabelForeColor = Color.White;
cht2.Series[0].ToolTip = "#VALX:#VAL(宗)"; //鼠標移動到對應點顯示數值
cht2.Series[0].ChartType = SeriesChartType.Pie; //圖類型(折線)
cht2.Series[0].Color = Color.Lime;
cht2.Series[0].LegendText = legend2.Name;
cht2.Series[0].IsValueShownAsLabel = true;
cht2.Series[0].LabelForeColor = Color.White;
cht2.Series[0].CustomProperties = "DrawingStyle = Cylinder";
cht2.Series[0].CustomProperties = "PieLabelStyle = Outside";
cht2.Legends.Add(legend2);
cht2.Legends[0].Position.Auto = true;
cht2.Series[0].IsValueShownAsLabel = true;
//是否顯示圖例
cht2.Series[0].IsVisibleInLegend = true;
cht2.Series[0].ShadowOffset = 0;
//餅圖折線
cht2.Series[0]["PieLineColor"] = "White";
//綁定數據
cht2.Series[0].Points.DataBindXY(x, y);
cht2.Series[0].Points[0].Color = Color.White;
//綁定顏色
cht2.Series[0].Palette = ChartColorPalette.BrightPastel;
#endregion
#region Bar圖
//標題
cht3.Titles.Add("交通違法行為TOP5");
cht3.Titles[0].ForeColor = Color.White;
cht3.Titles[0].Font = new Font("微軟雅黑", 12f, FontStyle.Regular);
cht3.Titles[0].Alignment = ContentAlignment.TopCenter;
cht3.Titles.Add("合計:25412 宗 ");
cht3.Titles[1].ForeColor = Color.White;
cht3.Titles[1].Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
cht3.Titles[1].Alignment = ContentAlignment.TopRight;
//控件背景
cht3.BackColor = Color.Transparent;
//圖表區背景
cht3.ChartAreas[0].BackColor = Color.Transparent;
cht3.ChartAreas[0].BorderColor = Color.Transparent;
//X軸標簽間距
cht3.ChartAreas[0].AxisX.Interval = 1;
cht3.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht3.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht3.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 14f, FontStyle.Regular);
cht3.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//X坐標軸顏色
cht3.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht3.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
cht3.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//X坐標軸標題
//cht3.ChartAreas[0].AxisX.Title = "數量(宗)";
//cht3.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
//cht3.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//cht3.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Auto;
//cht3.ChartAreas[0].AxisX.ToolTip = "數量(宗)";
//X軸網絡線條
cht3.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht3.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//Y坐標軸顏色
cht3.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht3.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
cht3.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//Y坐標軸標題
//cht3.ChartAreas[0].AxisY.Title = "數量(宗)";
//cht3.ChartAreas[0].AxisY.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
//cht3.ChartAreas[0].AxisY.TitleForeColor = Color.White;
//cht3.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Auto;
//cht3.ChartAreas[0].AxisY.ToolTip = "數量(宗)";
//Y軸網格線條
cht3.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht3.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht3.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht3.ChartAreas[0].AxisX.IsMarginVisible = false;
cht3.ChartAreas[0].Area3DStyle.Enable3D = true;
//背景漸變
cht2.ChartAreas[0].BackGradientStyle = GradientStyle.None;
//圖例樣式
Legend legend3 = new Legend("#VALX");
legend3.Title = "圖例";
legend3.TitleBackColor = Color.Transparent;
legend3.BackColor = Color.Transparent;
legend3.TitleForeColor = Color.White;
legend3.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
legend3.Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
legend3.ForeColor = Color.White;
cht3.Series[0].XValueType = ChartValueType.String; //設置X軸上的值類型
cht3.Series[0].Label = "#VAL"; //設置顯示X Y的值
cht3.Series[0].LabelForeColor = Color.White;
cht3.Series[0].ToolTip = "#VALX:#VAL(宗)"; //鼠標移動到對應點顯示數值
cht3.Series[0].ChartType = SeriesChartType.Bar; //圖類型(折線)
cht3.Series[0].Color = Color.Lime;
//cht3.Series[0].LegendText = legend3.Name;
cht3.Series[0].IsValueShownAsLabel = true;
cht3.Series[0].LabelForeColor = Color.White;
cht3.Series[0].CustomProperties = "DrawingStyle = Cylinder";
cht3.Series[0].CustomProperties = "PieLabelStyle = Outside";
//cht3.Legends.Add(legend3);
//cht3.Legends[0].Position.Auto = true;
//是否顯示圖例
cht3.Series[0].IsVisibleInLegend = true;
cht3.Series[0].ShadowOffset = 0;
//餅圖折線
cht3.Series[0]["PieLineColor"] = "White";
//綁定數據
cht3.Series[0].Points.DataBindXY(a, b);
//cht3.Series[0].Points[0].Color = Color.White;
//綁定顏色
cht3.Series[0].Palette = ChartColorPalette.BrightPastel;
//for (int n = 0; n < x.Length; n++)
//{
// int ptIdx = cht3.Series[0].Points.AddY(Convert.ToDouble(y[n]));
// DataPoint pt = this.cht3.Series[0].Points[ptIdx];
// pt.LegendText = x[n] + " " + "#PERCENT{P2}" + " [ " + "#VAL{D} 次" + " ]";//右邊標簽列顯示的文字
// pt.Label = x[n] + " " + "#PERCENT{P2}" + " [ " + "#VAL{D} 次" + " ]"; //圓餅外顯示的信息
// // pt.LabelToolTip = "#PERCENT{P2}";
// //pt.LabelBorderColor = Color.Red;//文字背景色
//}
#endregion
#region 雷達圖
// //標題
cht4.Titles.Add("交通違法行為TOP5");
cht4.Titles[0].ForeColor = Color.White;
cht4.Titles[0].Font = new Font("微軟雅黑", 12f, FontStyle.Regular);
cht4.Titles[0].Alignment = ContentAlignment.TopCenter;
cht4.Titles.Add("合計:25412 宗 ");
cht4.Titles[1].ForeColor = Color.White;
cht4.Titles[1].Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
cht4.Titles[1].Alignment = ContentAlignment.TopRight;
//控件背景
cht4.BackColor = Color.Transparent;
cht4.ChartAreas[0].BackColor = Color.Transparent;
cht4.ChartAreas[0].BorderColor = Color.Transparent;
//X軸標簽間距
cht4.ChartAreas[0].AxisX.Interval = 1;
cht4.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
cht4.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
cht4.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 14f, FontStyle.Regular);
cht4.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//X坐標軸顏色
cht4.ChartAreas[0].AxisX.LineColor = ColorTranslator.FromHtml("#38587a"); ;
cht4.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
cht4.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//X坐標軸標題
//cht4.ChartAreas[0].AxisX.Title = "數量(宗)";
//cht4.ChartAreas[0].AxisX.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
//cht4.ChartAreas[0].AxisX.TitleForeColor = Color.White;
//cht4.ChartAreas[0].AxisX.TextOrientation = TextOrientation.Auto;
//cht4.ChartAreas[0].AxisX.ToolTip = "數量(宗)";
//X軸網絡線條
cht4.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
cht4.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
//Y坐標軸顏色
cht4.ChartAreas[0].AxisY.LineColor = ColorTranslator.FromHtml("#38587a");
cht4.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
cht4.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微軟雅黑", 10f, FontStyle.Regular);
//Y坐標軸標題
//cht4.ChartAreas[0].AxisY.Title = "數量(宗)";
//cht4.ChartAreas[0].AxisY.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
//cht4.ChartAreas[0].AxisY.TitleForeColor = Color.White;
//cht4.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Auto;
//cht4.ChartAreas[0].AxisY.ToolTip = "數量(宗)";
//Y軸網格線條
cht4.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
cht4.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
cht4.ChartAreas[0].AxisY2.LineColor = Color.Transparent;
cht4.ChartAreas[0].AxisX.IsMarginVisible = false;
cht4.ChartAreas[0].Area3DStyle.Enable3D = true;
cht4.ChartAreas[0].AxisX.IsInterlaced = false;
cht4.ChartAreas[0].AxisX.IsMarginVisible = false;
//刻度線
cht4.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
//cht4.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
//cht4.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
//cht4.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
cht4.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
//背景漸變
cht4.ChartAreas[0].BackGradientStyle = GradientStyle.None;
//cht4.ChartAreas[0].AxisX2.InterlacedColor = Color.Red;
//cht4.ChartAreas[0].AxisY2.InterlacedColor = Color.Red;
//cht4.ChartAreas[0].BorderWidth = 0;
//cht4.ChartAreas[0].BackSecondaryColor = Color.Red;
//cht4.ChartAreas[0].BackImageTransparentColor = Color.Red;
//cht4.ChartAreas[0].AxisX.InterlacedColor = Color.Red;
//cht4.ChartAreas[0].AxisX.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisX2.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisX2.MajorGrid.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisX2.MajorTickMark.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisX2.MinorTickMark.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisY.InterlacedColor = Color.Red;
//cht4.ChartAreas[0].AxisY.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisY2.InterlacedColor = Color.Red;
//cht4.ChartAreas[0].AxisY2.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisY2.MajorGrid.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisY2.MajorTickMark.LineColor = Color.Red;
//cht4.ChartAreas[0].AxisY2.MinorTickMark.LineColor = Color.Red;
//圖例樣式
Legend legend4 = new Legend();
legend4.Title = "圖例";
legend4.TitleBackColor = Color.Transparent;
legend4.BackColor = Color.Transparent;
legend4.TitleForeColor = Color.White;
legend4.TitleFont = new Font("微軟雅黑", 10f, FontStyle.Regular);
legend4.Font = new Font("微軟雅黑", 8f, FontStyle.Regular);
legend4.ForeColor = Color.White;
cht4.Legends.Add(legend4);
cht4.Legends[0].Position.Auto = true;
//Series1
cht4.Series[0].XValueType = ChartValueType.String;
cht4.Series[0].Label = "#VAL";
cht4.Series[0].LabelForeColor = Color.White;
cht4.Series[0].ToolTip = "#LEGENDTEXT:#VAL(宗)";
cht4.Series[0].ChartType = SeriesChartType.Radar;
cht4.Series[0]["RadarDrawingStyle"] = "Line";
cht4.Series[0].LegendText = "2015年";
cht4.Series[0].IsValueShownAsLabel = true;
//Series2
cht4.Series.Add(new Series("Series2"));
cht4.Series[1].Label = "#VAL";
cht4.Series[1].LabelForeColor = Color.White;
cht4.Series[1].ToolTip = "#LEGENDTEXT:#VAL(宗)";
cht4.Series[1].ChartType = SeriesChartType.Radar;
cht4.Series[1]["RadarDrawingStyle"] = "Line";
cht4.Series[1].LegendText = "2016年";
cht4.Series[1].IsValueShownAsLabel = true;
//Series3
cht4.Series.Add(new Series("Series3"));
cht4.Series[2].Label = "#VAL";
cht4.Series[2].LabelForeColor = Color.White;
cht4.Series[2].ToolTip = "#LEGENDTEXT:#VAL(宗)";
cht4.Series[2].ChartType = SeriesChartType.Radar;
cht4.Series[2]["RadarDrawingStyle"] = "Line";
cht4.Series[2].LegendText = "2017年";
cht4.Series[2].IsValueShownAsLabel = true;
double[] yValues = { 65.62, 75.54, 60.45, 34.73, 85.42, 55.9, 63.6, 55.2, 77.1 };
string[] xValues = { "France", "Canada", "Germany", "USA", "Italy", "Spain", "Russia", "Sweden", "Japan" };
//Seris2
double[] y2 = { 45.62, 65.54, 70.45, 84.73, 35.42, 55.9, 63.6 };
double[] y3 = { 88.62, 35.54, 52.45, 45.73, 88.42, 14.9, 33.6 };
this.cht4.Series[0].Points.DataBindXY(xValues, yValues);
this.cht4.Series[1].Points.DataBindY(y2);
this.cht4.Series[2].Points.DataBindY(y3);
//設置X軸顯示間隔為1,X軸數據比較多的時候比較有用
cht4.ChartAreas[0].AxisX.LabelStyle.Interval = 1;
//設置XY軸標題的名稱所在位置位遠
cht4.ChartAreas[0].AxisX.TitleAlignment = StringAlignment.Near;
for (int i = 0; i < cht4.Series[2].Points.Count; i++)
{
cht4.Series[2].Points[i].MarkerStyle = MarkerStyle.Circle;//設置折點的風格
cht4.Series[2].Points[i].MarkerColor = Color.Red;//設置seires中折點的顏色
// cht4.Series[1].Points[i].MarkerStyle = MarkerStyle.Square;//設置折點的風格
// cht4.Series[1].Points[i].MarkerColor = Color.Blue;//設置seires中折點的顏色
// cht4.Series[2].Points[i].MarkerStyle = MarkerStyle.Square;//設置折點的風格
// cht4.Series[2].Points[i].MarkerColor = Color.Green;//設置seires中折點的顏色
}
for (int i = 0; i < cht4.Series.Count; i++)
{
for (int j = 0; j < cht4.Series[i].Points.Count; j++)
{
cht4.Series[i].Points[j].Label = " ";
//cht4.Series[i].Points[j].LabelToolTip = "string.Empty";
}
}
//cht4.ImageType = ChartImageType.Jpeg;
//反鋸齒
cht4.AntiAliasing = AntiAliasingStyles.All;
//調色板 磨沙:SemiTransparent
cht4.Palette = ChartColorPalette.BrightPastel;
cht4.Series[0].ChartType = SeriesChartType.Radar;
cht4.Series[1].ChartType = SeriesChartType.Radar;
cht4.Series[2].ChartType = SeriesChartType.Radar;
cht4.Width = 500;
cht4.Height = 350;
#endregion
/*
#VALX 顯示當前圖例的X軸的對應文本(或數據)
#VAL, #VALY, 顯示當前圖例的Y軸的對應文本(或數據)
#VALY2, #VALY3, 顯示當前圖例的輔助Y軸的對應文本(或數據)
#SER: 顯示當前圖例的名稱
#LABEL 顯示當前圖例的標簽文本
#INDEX 顯示當前圖例的索引
#PERCENT 顯示當前圖例的所占的百分比
#TOTAL 總數量
#LEGENDTEXT 圖例文本
*/
}
}

