欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

DevExpress之ChartControl的SeriesTemplate实例

程序员文章站 2023-12-18 13:09:46
本文实例讲述了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;
            }
        }
    }
}


运行效果:

DevExpress之ChartControl的SeriesTemplate实例

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

上一篇:

下一篇: