DevExpress.XtraCharts.chartControl

private Dictionary<string, double> chartPieDataDic = new Dictionary<string, double>();
private Dictionary<string, double> chartBarDataDic = new Dictionary<string, double>();
private void showPie()
{
ChartTitle title = new ChartTitle();
title.Text = "全省话务分析饼图-话务类型分布";

chartControl1.Titles.Clear();
chartControl1.Titles.Add(title);

Series series1 = new Series("话务类型", ViewType.Pie);
((PiePointOptions)series1.PointOptions).PointView = PointView.ArgumentAndValues;

foreach (KeyValuePair<string, double> keyvalue in chartPieDataDic)
{
series1.Points.Add(new SeriesPoint(keyvalue.Key, new double[] { keyvalue.Value }));
}

chartControl1.Series.Clear();
chartControl1.Series.Add(series1);
}
private void InitPieChartData()
{
try
{
chartPieDataDic.Add("大连", 0.2);
chartPieDataDic.Add("沈阳", 0.26);
chartPieDataDic.Add("锦州", 0.15);
chartPieDataDic.Add("盘锦", 0.15);
chartPieDataDic.Add("本溪", 0.1);
chartPieDataDic.Add("抚顺", 0.12);
chartPieDataDic.Add("营口", 0.02);
}
catch { }
}
private void InitBarChartData()
{
try
{
chartBarDataDic.Add("2001", 0.05);
chartBarDataDic.Add("2002", 0.02);
chartBarDataDic.Add("2003", 0.08);
chartBarDataDic.Add("2004", 0.15);
chartBarDataDic.Add("2005", 0.1);
chartBarDataDic.Add("2006", 0.3);
chartBarDataDic.Add("2007", 0.2);
chartBarDataDic.Add("2008", 0.1);
}
catch { }
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text.IndexOf("饼图") != -1)
{
showPie();
}
else if (comboBox1.Text.IndexOf("柱图") != -1)
{
showBar();
}
else if (comboBox1.Text.IndexOf("线图") != -1)
{
showLine();
}
else if (comboBox1.Text.IndexOf("点图") != -1)
{
showPoint();
}
else if (comboBox1.Text.IndexOf("ViewType") != -1)
{
BindData(ViewType.Line);
}
}
private void showBar()
{
try
{
ChartTitle title = new ChartTitle();
title.Text = "市网元容量增长率统计分析柱图";

chartControl1.Titles.Clear();
chartControl1.Titles.Add(title);

Series series2 = new Series("大连", ViewType.Bar);
Series series3 = new Series("沈阳", ViewType.Bar);
Series series4 = new Series("本溪", ViewType.Bar);
foreach (KeyValuePair<string, double> kvp in chartBarDataDic)
{
series2.Points.Add(new SeriesPoint(kvp.Key, new double[] { kvp.Value }));
series3.Points.Add(new SeriesPoint(kvp.Key, new double[] { kvp.Value + 0.08 }));
series4.Points.Add(new SeriesPoint(kvp.Key, new double[] { kvp.Value + 0.02 }));
}


chartControl1.Series.Clear();
chartControl1.Series.Add(series2);
chartControl1.Series.Add(series3);
chartControl1.Series.Add(series4);

chartControl1.Legend.Visible = true; // 显示标签(旁边的标注哪个颜色代表哪个城市)
}
catch { }
}
private void showLine()
{
ChartTitle title = new ChartTitle();
title.Text = "线图";
chartControl1.Titles.Clear();
chartControl1.Titles.Add(title);

Series series1 = new Series("辽宁", ViewType.Line);
series1.ArgumentScaleType = ScaleType.Numerical;

series1.Points.Add(new SeriesPoint(1, new double[] { 10 }));
series1.Points.Add(new SeriesPoint(2, new double[] { 12 }));
series1.Points.Add(new SeriesPoint(3, new double[] { 14 }));
series1.Points.Add(new SeriesPoint(4, new double[] { 17 }));
series1.Points.Add(new SeriesPoint(5, new double[] { 21 }));
series1.Points.Add(new SeriesPoint(6, new double[] { 26 }));
series1.Points.Add(new SeriesPoint(7, new double[] { 29 }));
series1.Points.Add(new SeriesPoint(8, new double[] { 30 }));

((PointSeriesView)series1.View).PointMarkerOptions.Kind = MarkerKind.Triangle;


Series series2 = new Series("山东", ViewType.Line);
series2.ArgumentScaleType = ScaleType.Numerical; //这句话必须有,否则点画不出来.
((LineSeriesView)series2.View).LineStyle.DashStyle = DashStyle.DashDotDot;
series2.Points.Add(new SeriesPoint(1, new double[] { 4 }));
series2.Points.Add(new SeriesPoint(2, new double[] { 14 }));
series2.Points.Add(new SeriesPoint(3, new double[] { 17 }));
series2.Points.Add(new SeriesPoint(4, new double[] { 22 }));
series2.Points.Add(new SeriesPoint(5, new double[] { 20 }));
series2.Points.Add(new SeriesPoint(6, new double[] { 15 }));
series2.Points.Add(new SeriesPoint(7, new double[] { 18 }));
series2.Points.Add(new SeriesPoint(8, new double[] { 11 }));

((PointSeriesView)series2.View).PointMarkerOptions.Kind = MarkerKind.Cross;

chartControl1.Series.Clear();
chartControl1.Series.Add(series1);
chartControl1.Series.Add(series2);
chartControl1.Legend.Visible = true;
}
private void showPoint()
{
ChartTitle title = new ChartTitle();
title.Text = "点图";
chartControl1.Titles.Clear();
chartControl1.Titles.Add(title);

Series series1 = new Series("上线人数", ViewType.Point);
series1.ArgumentScaleType = ScaleType.Numerical;

series1.Points.Add(new SeriesPoint(1, new double[] { 20 }));
series1.Points.Add(new SeriesPoint(2, new double[] { 12 }));
series1.Points.Add(new SeriesPoint(3, new double[] { 11 }));
series1.Points.Add(new SeriesPoint(4, new double[] { 17 }));
series1.Points.Add(new SeriesPoint(5, new double[] { 21 }));
series1.Points.Add(new SeriesPoint(6, new double[] { 21 }));
series1.Points.Add(new SeriesPoint(7, new double[] { 29 }));
series1.Points.Add(new SeriesPoint(8, new double[] { 30 }));

((PointSeriesView)series1.View).PointMarkerOptions.Kind = MarkerKind.Triangle;


Series series2 = new Series("下线人数", ViewType.Point);
series2.ArgumentScaleType = ScaleType.Numerical; //这句话必须有,否则点画不出来.

series2.Points.Add(new SeriesPoint(1, new double[] { 4 }));
series2.Points.Add(new SeriesPoint(2, new double[] { 14 }));
series2.Points.Add(new SeriesPoint(3, new double[] { 17 }));
series2.Points.Add(new SeriesPoint(4, new double[] { 22 }));
series2.Points.Add(new SeriesPoint(5, new double[] { 20 }));
series2.Points.Add(new SeriesPoint(6, new double[] { 15 }));
series2.Points.Add(new SeriesPoint(7, new double[] { 18 }));
series2.Points.Add(new SeriesPoint(8, new double[] { 11 }));

((PointSeriesView)series2.View).PointMarkerOptions.Kind = MarkerKind.Cross;

chartControl1.Series.Clear();
chartControl1.Series.Add(series1);
chartControl1.Series.Add(series2);
chartControl1.Legend.Visible = true;
}

posted on 2015-01-15 18:02  zrSoldier  阅读(1222)  评论(0编辑  收藏  举报