devexpress中用ChartControl生成柱状图

在界面中拖入一个ChartControl控件,然后添加一个simplebutton控件。在simplebutton控件的click事件中加入如下代码:

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()
        {
           
            IWorkspaceFactory pWorkspaceFactory = new  ShapefileWorkspaceFactory();//此处打开的shp 格式的数据
            //IWorkspaceFactory pWorkspaceFactory = new OleDbFactory();
            IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(@"D:\我的文档\道路边线", 0);
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

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

if (pFeatureWorkspace != null)
            {
                IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass("道路边线");
                IQueryFilter filter = new QueryFilterClass();
                filter.WhereClause = null;
                IFeatureCursor pFeatureCursor = pFeatureClass.Search(filter,false);
                IFeature pFeature = pFeatureCursor.NextFeature();
                string value = null;
                while (pFeature != null)
                {
                    int index = pFeatureClass.FindField("DWMC");
                    if (index != -1)
                    {
                        value = pFeature.get_Value(index).ToString();
                    }
                    if (value.Trim() == "城市道路(主干道)")
                    {
                        ZCityRoadNum++;
                    }
                    if (value.Trim() == "城市道路(次干道)")
                    {
                        CCityRoadNum++;
                    }
                    if (value.Trim() == "内部道路")
                    {
                        NRoadNum++;
                    }
                    if (value.Trim() == "单线标准轨")
                    {
                        DXBGNum++;
                    }
                    if (value.Trim() == "车挡")
                    {
                        CDNum++;
                    }
                    else
                    {
                        NullNum++;
                    }
                    pFeature = pFeatureCursor.NextFeature();
                }
            }

//建一个空表
            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;
         }
    }

时间: 2024-10-20 05:48:21

devexpress中用ChartControl生成柱状图的相关文章

Devexpress WPF ChartControl 多Y轴

<Window x:Class="DXApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/

Java读取数据库数据生成柱状图

此案例是用swing显示数据的.需要引入jfreechart相关包,不同版本可能包不相同,本人用的是 此案例在ssi框架下会报错,不用框架就没问题. Java后台逻辑代码: public class BarChart { ChartPanel frame1; public BarChart() { CategoryDataset dataset = getDataSet(); JFreeChart chart = ChartFactory.createBarChart3D("水果",

记一次非常无语的生成柱状图,js,ecshop。

如题,无语且非常郁闷. 要求是根据查询出来的数据动态生成柱状图.但是ecshop的查询ajax回调都是已经封装好了的.根本就不能改. 无奈之下只好百度了一个画柱状图的代码,每隔2秒抓取页面数据,重新绘制一次柱状图,假装自己是动态的.郁闷... 随便上个代码留个纪念,好歹做了三个小时.ummmm.... <canvas id="a_canvas" width="1000" height="700"></canvas> <

ArcGIS中用数据生成线和面的方法

1.首先将EXCEL中的数据导出为TXT格式的文本方档(格式参照以下注意问题及后面的数据格式). 2.打开ARCGIS,点击ARCGIS工具箱,找到Samples-data management-features-creat feature from text file,各参数设置参照注意问题及数据格式. ARCGIS中用数据生成线及面要注意的问题: Samples-data management-features-creat feature from text file Inpur decim

[DevExpress]ChartControl之柱状图演示

关键代码: using System; using System.Data; using System.Windows.Forms; using CSharpUtilHelpV2; using DevExpress.XtraCharts; namespace DevExpressChart { public partial class winProduct : Form { public winProduct() { InitializeComponent(); } static readonl

DevExpress中ChartControl柱状图(Bar)用法

我的数据 代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 chartControl1.Series.Clear();   // 柱状图里的第一个柱 Series Series1 = new Series("当年数据", ViewType.Bar); Series1.DataSource = data; Series1.ArgumentScaleType = ScaleType.Qualitative;

DevExpress之ChartControl用法

DevExpress中的ChartControl顾名思义就是数据基于图表展示,其关键在于Series上的处理. using System; using System.Drawing; using DevExpress.XtraCharts; namespace DevExpressUtilHelpV3 { public static class ChartToolV3 { /// <summary> /// 创建Series /// </summary> /// <param

DevExpress之ChartControl实现时间轴实例 z

using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; namespace DevExpressChart { public partial class winDateTime : Form { public winDateTime() { InitializeComponent(); } private void winDateTime_Load(object sende

【原】为DevExpress的ChartControl添加Y轴控制 和 GridControl中指定列添加超级链接

一.控制ChartControl的Y轴范围 使用Devexpress中的CharControl控件,需要控制AxisY轴的显示范围,需要使用该控件的BoundDataChanged事件,具体代码如下: 该代码实现的效果如下:   二.设置GridControl表格中的超级链接: 1.首先在表格的设计器中添加一个HyperLinkEdit 的 Repository: 2.将该Repository绑定到列表中的指定列中: 3.为第一步添加的rpLink控件添加Open_Link事件处理函数: 4.最