DevExpress之ChartControl的SeriesTemplate实例
本文实例讲述了devexpress之chartcontrol的seriestemplate用法,分享给大家供大家参考。具体方法如下:
关键代码如下:
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.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#程序设计有所帮助。
推荐阅读
-
DevExpress之ChartControl的SeriesTemplate实例
-
DevExpress之ChartControl实现时间轴实例
-
DevExpress之ChartControl创建Drill-Down样式的Title实例
-
DevExpress之ChartControl实现柱状图演示实例
-
DevExpress之TreeList用法实例总结
-
DevExpress之饼状图突出(Explode)设置实例
-
DevExpress之ChartControl用法实例总结
-
DevExpress之SplashScreen用法实例
-
ios获取数据之encodeURI和decodeURI的实例
-
iOS开发之获取LaunchImage启动图的实例