[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 readonly string AccessFullPath = string.Format(@"{0}\Northwind.MDB", AppDomain.CurrentDomain.BaseDirectory);
        static DataTable ProductList = null;
        AccessUtilsV2 AccessHelper = null;
        private void winChat_Load(object sender, EventArgs e)
        {
            AccessHelper = new AccessUtilsV2(AccessFullPath);
            ProductList = AccessHelper.ExecuteDataTable("select * from Products", null);
            BuilderDevChart();
        }
        private void BuilderDevChart()
        {
            if (ProductList != null)
            {
                Series _barSeries = new Series("测试", ViewType.Bar);
                _barSeries.ArgumentDataMember = "ProductName";//x轴
                _barSeries.ValueDataMembers[0] = "UnitPrice";//Y轴
                _barSeries.DataSource = ProductList;
                _barSeries.AddDataFilter("CategoryID", 4, DataFilterCondition.Equal);
                _barSeries.SetColorEach(true);
                chartControl1.Series.Add(_barSeries);
                _barSeries.LegendPointOptions.PointView = PointView.ArgumentAndValues;

                //chartControl1.SeriesDataMember = "UnitPrice";
                //chartControl1.SeriesTemplate.ValueDataMembers[0] = "UnitPrice";
                //chartControl1.SeriesTemplate.ArgumentDataMember = "ProductName";
                //chartControl1.SeriesTemplate.ArgumentScaleType = ScaleType.Qualitative;
                //chartControl1.SeriesTemplate.AddDataFilter("CategoryID", 4, DataFilterCondition.Equal);
                //chartControl1.SeriesTemplate.LegendPointOptions.PointView = PointView.ArgumentAndValues;
                chartControl1.SetXLableAngle(-35);
                chartControl1.SetCrosshair(true);

                chartControl1.Legend.Direction = LegendDirection.LeftToRight;
                chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center;
                chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.BottomOutside;
                chartControl1.DataSource = ProductList;

                chartControl1.AddTitle("Product List");
                //--------------------------
            }
        }
    }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }------------------------------------------------------------------------------------------------------

using DevExpress.Utils;
using DevExpress.XtraCharts;

namespace DevExpressChart
{
    public static class ChartUtils
    {
        /// <summary>
        /// 增加数据筛选
        /// </summary>
        /// <param name="SeriesBase">Series</param>
        /// <param name="columnName">列名称</param>
        /// <param name="value">列名称对应的筛选数值</param>
        /// <param name="dataFilterCondition">DataFilterCondition枚举</param>
        public static void AddDataFilter(this SeriesBase series, string columnName, object value, DataFilterCondition dataFilterCondition)
        {
            series.DataFilters.Add(new DataFilter(columnName, value.GetType().FullName, dataFilterCondition, value));
        }

        /// <summary>
        /// 设置X轴Lable角度
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="angle">角度</param>
        public static void SetXLableAngle(this ChartControl chart, int angle)
        {
            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;
            if (_xyDiagram != null)
                _xyDiagram.AxisX.Label.Angle = angle;
        }
        /// <summary>
        ///  设置Y轴Lable角度
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="angle">角度</param>
        public static void SetYLableAngle(this ChartControl chart, int angle)
        {
            XYDiagram _xyDiagram = (XYDiagram)chart.Diagram;
            _xyDiagram.AxisY.Label.Angle = angle;
        }
        /// <summary>
        /// 设置ColorEach
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="colorEach">是否设置成ColorEach</param>
        public static void SetColorEach(this Series series, bool colorEach)
        {
            SeriesViewColorEachSupportBase colorEachView = (SeriesViewColorEachSupportBase)series.View;
            if (colorEachView != null)
            {
                colorEachView.ColorEach = colorEach;
            }
        }
        /// <summary>
        /// 设置是否显示十字标线
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="crosshair">是否显示十字标线</param>
        public static void SetCrosshair(this ChartControl chart, bool crosshair)
        {
            chart.CrosshairEnabled = crosshair ? DefaultBoolean.True : DefaultBoolean.False;
            chart.CrosshairOptions.ShowArgumentLabels = crosshair;
            chart.CrosshairOptions.ShowArgumentLine = crosshair;
            chart.CrosshairOptions.ShowValueLabels = crosshair;
            chart.CrosshairOptions.ShowValueLine = crosshair;
        }
        /// <summary>
        /// 新增ChartControl的Title文字
        /// </summary>
        /// <param name="chart">ChartControl</param>
        /// <param name="title">Title文字</param>
        public static void AddTitle(this ChartControl chart, string title)
        {
            ChartTitle _title = new ChartTitle();
            _title.Text = title;
            chart.Titles.Add(_title);
        }
        /// <summary>
        /// 饼状Series设置成百分比显示
        /// </summary>
        /// <param name="series">Series</param>
        public static void SetPiePercentage(this Series series)
        {
            if (series.View is PieSeriesView)
            {
                ((PiePointOptions)series.PointOptions).PercentOptions.ValueAsPercent = true;
                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Format = NumericFormat.Percent;
                ((PiePointOptions)series.PointOptions).ValueNumericOptions.Precision = 0;
            }
        }
    }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }运行效果:

希望有所帮助!谢谢!

时间: 2024-10-22 12:30:48

[DevExpress]ChartControl之柱状图演示的相关文章

[DevExpress]ChartControl之SeriesTemplate演示

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

DevExpress ChartControl大数据加载时有哪些性能优化方法

DevExpress ChartControl加载大数据量数据时的性能优化方法有哪些? 关于图表优化,可从以下几个方面解决: 1.关闭不需要的可视化的元素(如LineMarkers, Labels等): Series.View.LineMarkerOptions.Visible =false. 2. 关闭图表的滚动与缩放功能,手动调整范围,这样将大大减少所需计算的个数. 3. 将 ChartControl.RefreshDataOnRepaint属性设为false 4. 将 ChartContr

DevExpress ChartControl 柱状图的使用【转】

//中心业务平台的“热门岗位信息监测”柱状图 public partial class HotJobInfo : UserControl     {         private object _objLock = new object(); private delegate void getDataHandler(); /// <summary>         /// 热门岗位数据         /// </summary>         private BarGragh

devexpress中用ChartControl生成柱状图

在界面中拖入一个ChartControl控件,然后添加一个simplebutton控件.在simplebutton控件的click事件中加入如下代码: private void button1_Click(object sender, EventArgs e)        {            //数据源            chartControl1.DataSource = CreateChartData();            //数据成员            chartCo

[DevExpress]ChartControl之饼状图百分比演示

关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; namespace DevExpressChart { public partial class winPieSeriesView : Form { public winPieSeriesView() { InitializeComponent(); } private DataTable CreateCh

WPF DevExpress ChartControl使用之XYDiagram

WPF使用Dev和WinForm有许多不同,相对而言,WPF要更简单和炫酷一点,我只做了一点基本的功能,没有仔细的研究,这里只介绍一下WPF Dev ChartControl绘制XYDiagram的基础. XYDiagramControl.xaml页面 <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microso

初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation

最近在用devexpress 第三方软件做项目. devexpress 的控件使用简单.功能强大.类型丰富.界面优美.扩展性强.今天主要是动态生成了一条StepLine.生成后的效果(能力不强,所以做的比较简单.): 首先,建立一个form(普通的或ribbonform均可),然后拖拽一个chartControl到form中.右键run warzid.然后将预设的线条删除(因为我们要动态添加). 然后查看form代码.在构造函数中添加方法调用InitCharControl(); 然后新建Init

[DevExpress]ChartControl之时间轴示例

关键代码: 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

[DevExpress]ChartControl之创建X,Y轴Title示例

关键代码: /// <summary> /// 设置X轴Title /// </summary> /// <param name="chart">ChartControl</param> /// <param name="titleText">Title文字</param> /// <param name="titleColor">Title文字颜色</pa