DevExpress.XtraCharts 画图

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraCharts;


{
    public partial class a: DevExpress.XtraEditors.XtraForm
    {
        public a()
        {
            InitializeComponent();
        }

        private Dictionary<stringdouble> chartPieDataDic = new Dictionary<stringdouble>();
        private Dictionary<stringdouble> chartBarDataDic = new Dictionary<stringdouble>();
        private void a_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("饼图");
            comboBox1.Items.Add("柱图");
            comboBox1.Items.Add("线图");
            comboBox1.Items.Add("点图");
            comboBox1.SelectedIndex = 0;
            InitPieChartData();
            InitBarChartData();
            showPie();

        }
        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<stringdouble> 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();
            }
        }

        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<stringdouble> 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(1new double[] { 10 }));
            series1.Points.Add(new SeriesPoint(2new double[] { 12 }));
            series1.Points.Add(new SeriesPoint(3new double[] { 14 }));
            series1.Points.Add(new SeriesPoint(4new double[] { 17 }));
            series1.Points.Add(new SeriesPoint(5new double[] { 21 }));
            series1.Points.Add(new SeriesPoint(6new double[] { 26 }));
            series1.Points.Add(new SeriesPoint(7new double[] { 29 }));
            series1.Points.Add(new SeriesPoint(8new 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(1new double[] { 4 }));
            series2.Points.Add(new SeriesPoint(2new double[] { 14 }));
            series2.Points.Add(new SeriesPoint(3new double[] { 17 }));
            series2.Points.Add(new SeriesPoint(4new double[] { 22 }));
            series2.Points.Add(new SeriesPoint(5new double[] { 20 }));
            series2.Points.Add(new SeriesPoint(6new double[] { 15 }));
            series2.Points.Add(new SeriesPoint(7new double[] { 18 }));
            series2.Points.Add(new SeriesPoint(8new 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(1new double[] { 20 }));
            series1.Points.Add(new SeriesPoint(2new double[] { 12 }));
            series1.Points.Add(new SeriesPoint(3new double[] { 11 }));
            series1.Points.Add(new SeriesPoint(4new double[] { 17 }));
            series1.Points.Add(new SeriesPoint(5new double[] { 21 }));
            series1.Points.Add(new SeriesPoint(6new double[] { 21 }));
            series1.Points.Add(new SeriesPoint(7new double[] { 29 }));
            series1.Points.Add(new SeriesPoint(8new double[] { 30 }));

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


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

            series2.Points.Add(new SeriesPoint(1new double[] { 4 }));
            series2.Points.Add(new SeriesPoint(2new double[] { 14 }));
            series2.Points.Add(new SeriesPoint(3new double[] { 17 }));
            series2.Points.Add(new SeriesPoint(4new double[] { 22 }));
            series2.Points.Add(new SeriesPoint(5new double[] { 20 }));
            series2.Points.Add(new SeriesPoint(6new double[] { 15 }));
            series2.Points.Add(new SeriesPoint(7new double[] { 18 }));
            series2.Points.Add(new SeriesPoint(8new 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 @ 2012-02-23 09:01  kenter  阅读(1756)  评论(0编辑  收藏  举报