//前台控件代码:WebChartControl控件:

<%-- 月采购量统计--%>
<dxchartsui:WebChartControl ID="WebChartControl1" runat="server" Width="700px" Height="400px" CssClass="chartsui"></dxchartsui:WebChartControl>

后台代码(cs)可写在自定义方法中:

​// 柱状图里的第一个柱

Series Series1 = new Series("金额", ViewType.Bar);

Series1.DataSource = dt;

Series1.ArgumentScaleType = ScaleType.Qualitative;

// 以哪个字段进行显示

Series1.ArgumentDataMember = "ymonth";

Series1.ValueScaleType = ScaleType.Numerical;

// 柱状图里的柱的取值字段

Series1.ValueDataMembers.AddRange(new string[] { "SUM(AMONEY)" });

// 柱状图里的第二柱

Series Series2 = new Series("采购数量", ViewType.Bar);

Series2.DataSource = dt;

Series2.ArgumentScaleType = ScaleType.Qualitative;

Series2.ArgumentDataMember = "ymonth";

Series2.ValueScaleType = ScaleType.Numerical;

Series2.ValueDataMembers.AddRange(new string[] { "sum(buynum)" });

ChartServices.SetChartTitle(this.WebChartControl1, true, "采购量图表统计", true, 2, StringAlignment.Center, ChartTitleDockStyle.Top, true, new Font("宋体", 12, FontStyle.Bold), Color.Red, 10);    //显示图表标题

for (int i = 0; i < dt.Rows.Count; i++)

{

// string tt = dt.Rows[i]["ymonth"].ToString();

SeriesPoint point1 = new SeriesPoint(dt.Rows[i]["ymonth"].ToString(), Convert.ToDouble(dt.Rows[i]["SUM(AMONEY)"].ToString()));

SeriesPoint point2 = new SeriesPoint(dt.Rows[i]["ymonth"].ToString(), Convert.ToDouble(dt.Rows[i]["sum(buynum)"].ToString()));

Series1.Points.Add(point1);

Series2.Points.Add(point2);

}

WebChartControl1.Series.Add(Series1);

WebChartControl1.Series.Add(Series2);

ChartServices类文件代码(用于设置WebChartControl中标题,颜色、值等属性)--一般在前端WebChartControl有自带的属性,有时点不出来时,则可以引用。

class ChartServices

{

///

/// 绘制图形

///

/// 图表控件

/// 系列名

/// 类型

/// 数据源

///

///

public static void DrawChart(DevExpress.XtraCharts.Web.WebChartControl control, string seriesName, ViewType type, DataTable dt, string column1, string column2)

{

Series series = new Series(seriesName, type);

DataTable table = dt;

SeriesPoint point = null;

for (int i = 0; i < table.Rows.Count; i++)

{

point = new SeriesPoint(table.Rows[i][column1].ToString(), Convert.ToDouble(table.Rows[i][column2].ToString()));

series.Points.Add(point);

}

control.Series.Add(series);

//针对饼图的特殊处理

if (type == ViewType.Pie)

{

//设置显示方式(Argument:显示图例说明,ArgumentAndValues:显示图例内容和数据)

series.Label.PointOptions.PointView = PointView.ArgumentAndValues;

//设置数据显示形式(Percent:百分比,Currency:货币类型,数据前添加¥,Scientific:科学计数法)

series.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

//数据是否保留小数(0:不保留小数位,1保留一位小数,2保留两位小数)

series.Label.PointOptions.ValueNumericOptions.Precision = 0;

//数据以百分比显示时只能是Default和None

((PieSeriesLabel)series.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default;

}

}

///

/// 设置图表标题

///

/// 图表控件

/// /// 标题是否可见

/// 标题文本

/// 是否换行

/// 最大允许行数

/// 对齐方式

/// 位置

/// 是否允许设置外观

/// 字体

/// 文本颜色

/// 字体缩进值

public static void SetChartTitle(DevExpress.XtraCharts.Web.WebChartControl control, bool isVisible, String text, bool isWordWrop, int maxLineCount, StringAlignment alignment, ChartTitleDockStyle dock, bool isAntialiasing, Font font, Color textColor, int indent)

{

//设置标题

ChartTitle title = new ChartTitle();

title.Visible = isVisible;

//显示文本

title.Text = text;

//是否允许换行

title.WordWrap = isWordWrop;

//最大允许行数

title.MaxLineCount = maxLineCount;

//对齐方式

title.Alignment = alignment;

//位置

title.Dock = dock;

//是否允许设置外观

title.Antialiasing = isAntialiasing;

//字体

title.Font = font;

//字体颜色

title.TextColor = textColor;

//缩进值

title.Indent = indent;

control.Titles.Add(title);

}

///

/// 为X轴添加标题

///

/// 图形控件

/// 标题是否可见

/// 对齐方式

/// 标题显示文本

/// 标题字体颜色

/// 是否允许设置外观

/// 字体

public static void SetAxisX(DevExpress.XtraCharts.Web.WebChartControl control, bool isVisible, StringAlignment aligment, string text, Color color, bool isAntialiasing, Font font)

{

XYDiagram xydiagram = (XYDiagram)control.Diagram;

xydiagram.AxisX.Title.Visible = isVisible;

xydiagram.AxisX.Title.Alignment = aligment;

xydiagram.AxisX.Title.Text = text;

xydiagram.AxisX.Title.TextColor = color;

xydiagram.AxisX.Title.Antialiasing = isAntialiasing;

xydiagram.AxisX.Title.Font = font;

}

///

/// 为X轴添加标题

///

/// 图形控件

/// 标题是否可见

/// 对齐方式

/// 标题显示文本

/// 标题字体颜色

/// 是否允许设置外观

/// 字体

public static void SetAxisY(DevExpress.XtraCharts.Web.WebChartControl control, bool isVisible, StringAlignment aligment, string text, Color color, bool isAntialiasing, Font font)

{

XYDiagram xydiagram = (XYDiagram)control.Diagram;

xydiagram.AxisY.Title.Visible = isVisible;

xydiagram.AxisY.Title.Alignment = aligment;

xydiagram.AxisY.Title.Text = text;

xydiagram.AxisY.Title.TextColor = color;

xydiagram.AxisY.Title.Antialiasing = isAntialiasing;

xydiagram.AxisY.Title.Font = font;

}

}

Devexpress中WebChartControl控件柱状统计图的做法(数据为调用存储过程)的更多相关文章

  1. 玩转控件:重绘DEVEXPRESS中DateEdit控件 —— 让DateEdit支持只选择年月 (提供源码下载)

      前言 上一篇博文<玩转控件:重绘ComboBox —— 让ComboBox多列显示>中,根据大家的回馈,ComboBox已经支持筛选了,更新见博文最后最后最后面.   奇葩 这两天遇到 ...

  2. Android中查看布局文件中的控件(view,id)在哪里被调用(使用)

    在阅读别人的代码时通常是很痛苦的,有时很想要看一看布局中的控件在哪里被调用了,为之很苦恼 在这里提供一种方法.   复制要查看的控件ID,到R文件中搜索到该ID,   接下来就好办的了,选中ID按下C ...

  3. WPF中TreeView控件数据绑定和后台动态添加数据(二)

    写在前面:在(一)中,介绍了TreeView控件MVVM模式下数据绑定的方法.在这篇文章中,将总结给节点添加事件的方法,这样说有些不对,总之实现的效果就是点击某个节点,将出现对应于该节点的页面或者数据 ...

  4. WPF中TreeView控件数据绑定和后台动态添加数据(一)

    数据绑定: 更新内容:补充在MVVM模式上的TreeView控件数据绑定的代码. xaml代码: <TreeView Name="syntaxTree" ItemsSourc ...

  5. 【转】使用DevExpress的WebChartControl控件绘制图表(柱状图、折线图、饼图)

    第一次写博,没什么经验,主要是把最近自己对Dev的一些研究贴出来大家共同探讨,有不足之处望大家帮忙斧正. WebChartControl是DevExpress控件群下的一个Web图表控件,它使用非常的 ...

  6. devexpress中gridview控件编辑时改变输入法状态

    在win7环境下使用Devexpress中的SpinEdit控件,切换成中文[简/繁]输入法输入数字键时有不少输入法会重复产生数字如输入1会变成11,输入123会变成112233.使用SpinEdit ...

  7. DevExpress中 TreeList控件的常规配置

    //以下为TreeList控件样式相关设置 this.treelist_SystemCfg.BackColor = Color.Transparent; this.treelist_SystemCfg ...

  8. devexpress中ASPxGridView控件初始化赋值

    写在ASPxGridView中OnCellEditorInitialize="ASPxGridView_progoods_CellEditorInitialize"  事件中: / ...

  9. DevExpress中XtraGrid控件对GridView每行的颜色设置 zt

    改变行颜色 private void GridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArg ...

随机推荐

  1. (四)java程序基本组成

    一个基本的java程序一般包括几个部分,分别是程序所在的包名.程序中用到的其他包的路径.程序的类.类中的方法.变量和字面量. package demo; import java.util.Date; ...

  2. Learning Core Data 1

    What is Core Data? If you want to build anything beyond the most simplistic apps for iOS, you’ll nee ...

  3. C#继承的用法

    using System; namespace 继承 { public class cat { private string _name = null; private int _age = 0; p ...

  4. Top 6 Programming Languages for Mobile App Development

    Mobile application development industry in the last five years have multiplied in leaps and bounds, ...

  5. sudo gem install cocoapods

    在使用IOS_BaiduSDK的时候,需要用到cocoapods,所以就需要按照步骤继续着.但是在过程中会遇到一些问题: 1. sudo gem install cocoapods 运行这个报错 Ru ...

  6. Tomcat启动过程原理详解

    基于Java的Web 应用程序是 servlet.JSP 页面.静态页面.类和其他资源的集合,它们可以用标准方式打包,并运行在来自多个供应商的多个容器.Web 应用程序存在于结构化层次结构的目录中,该 ...

  7. CentOS修改163源(转载)

    From:http://www.linuxidc.com/Linux/2012-08/69043.htm #CentOS-Base.repo其他版本文件在http://mirrors.163.com/ ...

  8. eclipse导出jar包

    第一种:普通类导出jar包,我说的普通类就是指此类包含main方法,并且没有用到别的jar包. 1.在eclipse中选择你要导出的类或者package,右击,选择Export子选项: 2.在弹出的对 ...

  9. java静态代理

    WorkIF.java package com.wzh.test; public interface WorkIf { void doWork(String name);} work.java pac ...

  10. Restful API的设计与实践

    Restful这个名称应该很多人都不陌生,但是我发现不少人对Restful存在或多或少的理解偏差,其中不泛比较厉害的程序员,所以有必要为Restful来“正名”. Restful是一种软件架构风格,设 ...