柱状图 C# 基于Oracle数据库

添加引用:

using DevExpress.XtraCharts;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using System.Data.OleDb;
using ESRI.ArcGIS.esriSystem;
using System.Data.OracleClient;

 

代码:

加一个Button按钮

        private void button1_Click(object sender, EventArgs e)
        {

            //数据源
            chartControl1.DataSource = CreateChartData();
            //数据成员
            chartControl1.SeriesDataMember = "DWMC";
            //下面显示
            chartControl1.SeriesTemplate.ArgumentDataMember = "DWMC";

            chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] {"Value"});

            chartControl1.SeriesTemplate.View = new StackedBarSeriesView();
            chartControl1.Titles.Add(new ChartTitle());
            chartControl1.Titles[0].Text = "道路类型统计图";


        }
        private DataTable CreateChartData()
        {
            string connection = "Data Source = GIS;user = gis; password = jnsz";//数据库的连接 数据源 用户 密码
            OracleConnection coon = new OracleConnection(connection);//建立数据库连接

            OracleCommand cmd = new OracleCommand("select DWMC from 道路边线  ", coon);//执行数据连接

            DataSet ds1;

            ds1 = new DataSet();//定义数据集

            OracleDataAdapter da1 = new OracleDataAdapter(cmd);//取出数据表
            da1.Fill(ds1);//将数据加载到数据集中

            DataTable dt = ds1.Tables[0];//将数据放入表中

            coon.Close();//关闭数据库连接

            int ZCityRoadNum = 0, CCityRoadNum = 0, NRoadNum = 0, DXBGNum = 0, NullNum = 0, CDNum = 0;//城市道路(主干道)、城市道路(次干道)、内部道路、单线标准轨、空、车档

            string Value;
            ///遍历
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Value = dt.Rows[i]["DWMC"].ToString();
                if (Value.Trim() == "城市道路(主干道)")
                {
                    ZCityRoadNum++;
                }
                if (Value.Trim() == "城市道路(次干道)")
                {
                    CCityRoadNum++;
                }
                if (Value.Trim() == "内部道路")
                {
                    NRoadNum++;
                }
                if (Value.Trim() == "单线标准轨")
                {
                    DXBGNum++;
                }
                if (Value.Trim() == "车挡")
                {
                    CDNum++;
                }
                else
                {
                    NullNum++;
                }
            }
       
            //建一个空表
            DataTable table = new DataTable("DLBX_DWMC");

            //列
            table.Columns.Add("DWMC", typeof(string));

            table.Columns.Add("Value", typeof(Decimal));

            //行
            table.Rows.Add(new object[] { "城市主干道", ZCityRoadNum });
            table.Rows.Add(new object[] { "城市次干道", CCityRoadNum });
            table.Rows.Add(new object[] { "内部道路", NRoadNum });
            table.Rows.Add(new object[] { "单线标准轨", DXBGNum });
            table.Rows.Add(new object[] { "车挡", CDNum });
            table.Rows.Add(new object[] { "无", NullNum });
            return table;

        }

 

你可能感兴趣的:(柱状图 C# 基于Oracle数据库)