1.属性
1.1 Series
Char1.Legends["Legend" + i].LegendStyle = LegendStyle.Column;//按列显示
Char1.Legends["Legend" + i].Docking = Docking.Right;//显示在右上角;
Char1.Series[seriesName].BorderWidth = 3;
//节点大小为5
Char1.Series[seriesName].MarkerSize = 7;
Char1.Series[seriesName].IsVisibleInLegend = false;
1.2 ChartAreas
Chart1.ChartAreas[0].AxisX.Interval = 1; //设置X轴坐标的间隔为1 Chart1.ChartAreas[0].AxisX.IntervalOffset = 1; //设置X轴坐标偏移为1 Chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true; //设置是否交错显示,比如数据多的时候分成两行来显示
//在y轴上有交点 Char1.ChartAreas["ChartAreasValue"].AxisX.IsMarginVisible = false; Char1.Titles.Add(string.Format("{0}年勘测设计产值完成情况", this.ddlSearchYear.SelectedValue)); Char1.ChartAreas["ChartAreasValue"].AxisY.Title = "单位:万元";
1.3 图表
ChartDataTableHelper TableHelper = new ChartDataTableHelper(); //显示合计 TableHelper.Initialize(Char1,false);
2.绑定
2.1
//一个柱子 DataRow[] dtChartData = DsResult.Tables["DtDeptResult"].Select("1=1"); string xValueMember = "DeptName"; string yValueMembers = "AllMark"; chartDeptMark.DataSource = dtChart.DefaultView; chartDeptMark.Series.Add("Series1"); chartDeptMark.Series["Series1"].XValueMember = xValueMember; chartDeptMark.Series["Series1"].YValueMembers = yValueMembers; //一条数据中的多列对应多个Y值 DataRow[] drResult = GetValueOfYear().Select("StatYear=100"); for (int i = 0; i < 12; i++) { if (startMonth > 12) { startMonth -= 12; } montharr[i] = startMonth; string columnName = "CVM" + startMonth; Char1.Series["Series0"].Points.AddXY(startMonth.ToString(), drResult[0][columnName]); //Char1.Series["Series0"].XValueMember = montharr; startMonth++; } //多行数据 for (int i = 0; i < dtResult.Columns.Count; i++) { string columnName = dtResult.Columns[i].ColumnName; string seriesName = "Series" + i; Char1.Series.Add(seriesName); Char1.Series[seriesName].Points.DataBindXY (dtResult.DefaultView, "BelongType", dtResult.DefaultView, columnName); }
2.2 分裂饼图
DataTable dtResult = GetResult(); Char1.Series.Add("serie0"); Char1.Series["serie0"].Points.DataBind(dtResult.DefaultView, "BelongType", "BelongTypeRatio", "LegendText=" + "BelongType"); Char1.Series["serie0"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Pie", true); Char1.Legends.Add("Legend0"); Char1.Series["serie0"].Label = "#LEGENDTEXT:#PERCENT{P}"; Char1.Series["serie0"]["PieLabelStyle"] = "Outside"; ////对否将值作为标签来显示 Char1.Series["serie0"].IsValueShownAsLabel = true; //分裂图 foreach (DataPoint point in Char1.Series["serie0"].Points) { point["Exploded"] = "true"; }
3.事件
//对图中的图形添加单击事件,该例子是单击柱子后调用前台函数,跳转详细页面 chartDeptMark.Series["Series1"].MapAreaAttributes = "onclick=\"javascript:return DeptMark('#VALX');\"";