首页 > 编程 > C# > 正文

C#中dotnetcharting的用法实例详解

2019-10-29 21:44:25
字体:
来源:转载
供稿:网友
这篇文章主要介绍了C#中dotnetcharting的用法,以实例形式详细分析了基于dotnetcharting的图表绘制的各种常用方法,是非常实用的技巧,需要的朋友可以参考下
 

本文以实例形式详细讲述了dotnetcharting控件的用法。分享给大家供大家参考。具体用法分析如下:

dotnetcharting 是一个很好用的图表控件,能画出很漂亮的报表,一般常用到的主要有柱状图、饼图、折线图三种。
dotnetcharting 有web版、winform版多个版本可供使用,官方网址:http://www.dotnetcharting.com/ ,官网有很多示例(http://www.dotnetcharting.com/gallery/),而且有winform安装版示例和代码,如下图。
dotnetcharting 有网上破解版的,去百度或谷歌一搜一堆。
说下个人感受,该控件是国外开发的,虽然说这个控件挺好用的,但是感觉这个控件应该在有xp系统的时候就应该有了吧?是国外剩下的技术,咱们一直在用别人不用的技术,捧为珍宝。
有些技术有些人,有些本事就开始自大起来,小有成就的那点技术还藏着掖着。 呵呵。。。

C#中dotnetcharting的用法实例详解

接下来上干货,前两天刚使用dotnetcharting 做了个统计报表,代码如下:
 

复制代码代码如下:
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using dotnetCHARTING.WinForms;
using StationChart.Model;
using StationChart.Utility;
using Chart = dotnetCHARTING.WinForms.Chart;
using Series = dotnetCHARTING.WinForms.Series;
using SeriesCollection = dotnetCHARTING.WinForms.SeriesCollection;
 
namespace ManageSystem
{
    // <summary>
    // 作者:薛江涛
    // 版本:V1.0.0
    // 时间:2014/10/9 11:49:48
    // </summary>
    public class ShowData
    {
        #region 属性
        private string _phaysicalimagepath;//图片存放路径
        private string _xtitle;//图片x座标名称
        private string _ytitle;//图片y座标名称
        private string _seriesname;//图例名称
        private int _picwidth;//图片宽度
        private int _pichight;//图片高度
        private DataTable _dt;//图片数据源
        private DataSet _ds;//图片数据源
 
        private Color _titleBoxColor;//图片标题背景色
        private Font _titleBoxFont;//图片标题字体
        private Color _chartAreaBackgroundColor;//图片背景颜色
        private Font _xAxisLabelFont;//X轴柱状图值字体
        private Font _yAxisLabelFont;//Y轴柱状图值字体
        private Font _xAxisDefaultTickLabelFont;//X轴刻度字体
        private Font _yAxisDefaultTickLabelFont;//Y轴刻度字体
        private SeriesType _chartDefaultSeriesType;//图片类型
        private ChartType _chartType;//图片类型
        //private bool _isMonth; //是否是月显示
        private int _staticColumnWidth;//设置柱状图每个单元格的宽度
        private int _numberPercision;//设置数值小数点
 
        /// <summary>
        /// 图片存放路径
        /// </summary>
        public string PhaysicalImagePath
        {
            set { _phaysicalimagepath = value; }
            get { return _phaysicalimagepath; }
        }
 
        /// <summary>
        /// 图片标题
        /// </summary>
        public string Title { get; set; }
 
        /// <summary>
        /// 图片标题
        /// </summary>
        public string XTitle
        {
            set { _xtitle = value; }
            get { return _xtitle; }
        }
        /// <summary>
        /// 图片标题
        /// </summary>
        public string YTitle
        {
            set { _ytitle = value; }
            get { return _ytitle; }
        }
 
        /// <summary>
        /// 图例名称
        /// </summary>
        public string SeriesName
        {
            set { _seriesname = value; }
            get { return _seriesname; }
        }
        /// <summary>
        /// 图片宽度
        /// </summary>
        public int PicWidth
        {
            set { _picwidth = value; }
            get { return _picwidth; }
        }
        /// <summary>
        /// 图片高度
        /// </summary>
        public int PicHight
        {
            set { _pichight = value; }
            get { return _pichight; }
        }
        /// <summary>
        /// 图片数据源
        /// </summary>
        public DataTable DataSource
        {
            set { _dt = value; }
            get { return _dt; }
        }
        /// <summary>
        /// 图片数据源
        /// </summary>
        public DataSet DataSetSource
        {
            set { _ds = value; }
            get { return _ds; }
        }
 
        public int NumberPercision
        {
            set { _numberPercision = value; }
            get { return _numberPercision; }
        }
 
        public Color TitleBoxColor
        {
            get { return _titleBoxColor; }
            set { _titleBoxColor = value; }
        }
 
        public Font TitleBoxFont
        {
            get { return _titleBoxFont; }
            set { _titleBoxFont = value; }
        }
 
        public Color ChartAreaBackgroundColor
        {
            get { return _chartAreaBackgroundColor; }
            set { _chartAreaBackgroundColor = value; }
        }
 
        public Font XAxisLabelFont
        {
            get { return _xAxisLabelFont; }
            set { _xAxisLabelFont = value; }
        }
 
        public Font YAxisLabelFont
        {
            get { return _yAxisLabelFont; }
            set { _yAxisLabelFont = value; }
        }
 
        public Font XAxisDefaultTickLabelFont
        {
            get { return _xAxisDefaultTickLabelFont; }
            set { _xAxisDefaultTickLabelFont = value; }
        }
 
        public Font YAxisDefaultTickLabelFont
        {
            get { return _yAxisDefaultTickLabelFont; }
            set { _yAxisDefaultTickLabelFont = value; }
        }
 
        public SeriesType ChartDefaultSeriesType
        {
            get { return _chartDefaultSeriesType; }
            set { _chartDefaultSeriesType = value; }
        }
 
        public ChartType ChartType
        {
            get { return _chartType; }
            set { _chartType = value; }
        }
 
        //public bool IsMonth
        //{
        // get { return _isMonth; }
        // set { _isMonth = value; }
        //}
 
 
        public ModelConseme.DateChartEnum SeriesTypeE { get; set; }
 
        public int StaticColumnWidth
        {
            get { return _staticColumnWidth; }
            set { _staticColumnWidth = value; }
        }
 
        #endregion
 
        #region 构造函数
        public ShowData()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
            NumberPercision = 2;
        }
 
        public ShowData(string phaysicalImagePath, string title, string xTitle, string yTitle, string seriesName)
        {
            _phaysicalimagepath = phaysicalImagePath;
            style="border-left-color: rgb(0, 153, 204); border-left-width: 1px; border-left-style: solid; padding: 0px 3px; margin: 3px auto 0px; width: 640px; background-color: rgb(242, 246, 251); clear: both; border-top-color: rgb(0, 153, 204); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(0, 153, 204); border-right-width: 1px; border-right-style: solid;"> 复制代码代码如下:
ShowData show = new ShowData();
//show.PicHight = 494;
//show.PicWidth = 1336;
show.SeriesName = "具体详情";
show.PhaysicalImagePath = "ChartImages";
show.TitleBoxColor = Color.Blue;
show.TitleBoxFont = new Font("Arial", 10, FontStyle.Bold);
show.ChartAreaBackgroundColor = Color.Honeydew;
show.XAxisLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.YAxisLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.XAxisDefaultTickLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.YAxisDefaultTickLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.ChartDefaultSeriesType = SeriesType.Column;
show.DataSetSource = dsSet;
show.SeriesTypeE = modelConseme.DateChart;

 

//饼图
show.YTitle = "油量(升)";
//show.Title = strOils + strDate + strConsume + "销售油量报表统计图";  
show.XTitle = "";
show.DataSource = dsSet.Tables[0];
show.CreatePie(this.chart1);

//柱状图(两条柱子对比)
 show.YTitle = "油量(升)";
label2.Text = strDate + strOils + strConsume + @"油品对比图";
show.XTitle = "油品";
//show.DataSource = dsSet.Tables[2];
show.StaticColumnWidth = 0;
show.CreateColumn(chart2, new List<int>()
{
0,
1
});

//曲线图
show.YTitle = "油量(升)";
label5.Text = strDate + strOils + strConsume + @"油量环比图";
show.XTitle = "时间";
show.DataSource = dsSet.Tables[4];
show.CreateLine(this.chart5);

//单个柱子
var show = new ShowData
{
    src="/uploads/allimg/150116/124253L45-1.png?201492991845" style="border: 1px solid rgb(204, 204, 204); padding: 3px; max-width: 620px; overflow: hidden;" />

C#中dotnetcharting的用法实例详解

C#中dotnetcharting的用法实例详解

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表