DevExpress之ChartControl的SeriesTemplate实例

本文实例讲述了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 AccessFullPath = string.Format(@"{0}\gsp.mdb", AppDomain.CurrentDomain.BaseDirectory);
        static DataTable GspList = null;
        AccessUtilsV2 AccessHelper = null;
        private void winGsp_Load(object sender, EventArgs e)
        {

AccessHelper = new AccessUtilsV2(AccessFullPath);
            GspList = AccessHelper.ExecuteDataTable("select * from Gsp", null);
            BuilderDevChart();
        }
        private void BuilderDevChart()
        {
            if (GspList != null)
            {
                chartControl1.SeriesDataMember = "Year";
                chartControl1.SeriesTemplate.ArgumentDataMember = "Region";
                chartControl1.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "GSP" });
                chartControl1.SeriesNameTemplate.BeginText = "GSP in ";
                chartControl1.DataSource = GspList;

chartControl1.SetXLableAngle(-35);
                chartControl1.SetCrosshair(true);

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

chartControl1.AddTitle("GSP List");
            }
        }
    }
}

代码如下:

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;
            }
        }
    }
}

运行效果:

希望本文所述对大家的C#程序设计有所帮助。

(0)

相关推荐

  • DevExpress实现为TextEdit设置水印文字的方法

    本文实例展示了DevExpress实现为TextEdit设置水印文字的方法,是一个很实用的技巧.分享给大家供大家参考. 关键代码如下: public static void SetWatermark(this TextEdit textEdit, string watermark) { textEdit.Properties.NullValuePromptShowForEmptyValue = true; textEdit.Properties.NullValuePrompt = waterma

  • DevExpress之ChartControl实现饼状图百分比演示实例

    本文实例讲述了DevExpress中ChartControl实现饼状图百分比演示的方法.分享给大家供大家参考.具体实现方法如下: 关键代码如下: 复制代码 代码如下: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; namespace DevExpressChart {     public partial class winPieSeriesView : Form

  • DevExpress之饼状图突出(Explode)设置实例

    本文实例讲述了DevExpress之饼状图突出(Explode)设置方法,分享给大家供大家参考.具体实现方法如下: 关键代码如下: 复制代码 代码如下: /// <summary> /// 饼状图突出设置 /// </summary> /// <param name="chart">ChartControl</param> /// <param name="pieSeries">Series[仅仅适用于Pi

  • DevExpress获取节点下可视区域子节点集合的实现方法

    递归获取节点是很多程序项目中常见的技巧.本文就以实例展示了DevExpress获取节点下可视区域子节点集合的实现方法.分享给大家供参考之用,具体方法如下: 关键部分代码如下: /// <summary> /// 向下递归TreeListNode节点 /// </summary> /// <param name="node">需要向下递归的节点</param> /// <param name="conditionHanlde

  • DevExpress设置饼状图的Lable位置实例

    本文实例讲述了DevExpress设置饼状图的Lable位置的方法.分享给大家供大家参考.具体实现方法如下: 关键代码如下: 复制代码 代码如下: /// <summary> /// 设置饼状图的Lable位置 /// </summary> /// <param name="series">Series</param> /// <param name="lablePosition">PieSeriesLab

  • DevExpress之ChartControl用法实例总结

    DevExpress中的ChartControl顾名思义就是数据基于图表展示,其关键在于Series上的处理.本文实例展示了ChartControl的用法,具体内容如下: 主要功能代码部分如下: using System; using System.Drawing; using DevExpress.XtraCharts; namespace DevExpressUtilHelpV3 { public static class ChartToolV3 { /// <summary> /// 创

  • DevExpress之ChartControl实现柱状图演示实例

    本文实例讲述了DevExpress中ChartControl实现柱状图演示的方法.分享给大家供大家参考.具体实现方法如下: 关键代码如下: 复制代码 代码如下: using System; using System.Data; using System.Windows.Forms; using CSharpUtilHelpV2; using DevExpress.XtraCharts; namespace DevExpressChart {     public partial class wi

  • DevExpress之TreeList用法实例总结

    本文实例总结了DevExpress之TreeList用法,希望对大家学习C#程序设计起到一定的帮助作用.具体实例如下: using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraBars; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Node

  • DevExpress之SplashScreen用法实例

    本文实例展示了DevExpress中SplashScreen的用法,对于C#初学者来说有一定的参考借鉴价值,具体用法如下: 关键代码部分如下: using DevExpress.XtraSplashScreen; using System; namespace DevExpressUtilHelpV3 { /// <summary> /// 基于.NET 3.0的 SplashScreen工具类 /// </summary> public static class SplashSc

  • DevExpress之ChartControl实现时间轴实例

    本文实例讲述了DevExpress采用ChartControl实现时间轴的方法,分享给大家供大家参考.具体实现方法如下: 关键代码如下: 复制代码 代码如下: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; namespace DevExpressChart {     public partial class winDateTime : Form     {   

  • DevExpress之ChartControl创建Drill-Down样式的Title实例

    本文实例讲述了DevExpress中ChartControl创建Drill-Down样式的Title实现方法.分享给大家供大家参考.具体实现方法如下: 关键代码如下: 复制代码 代码如下: /// <summary> /// 创建Drill-Down样式的Title /// </summary> /// <param name="chart">ChartControl</param> /// <param name="ti

随机推荐