DevExpress之ChartControl实现饼状图百分比演示实例
本文实例讲述了devexpress中chartcontrol实现饼状图百分比演示的方法。分享给大家供大家参考。具体实现方法如下:
关键代码如下:
using system.data;
using system.windows.forms;
using devexpress.xtracharts;
namespace devexpresschart
{
public partial class winpieseriesview : form
{
public winpieseriesview()
{
initializecomponent();
}
private datatable createchartdata()
{
datatable table = new datatable("table1");
table.columns.add("name", typeof(string));
table.columns.add("value", typeof(int32));
table.rows.add(new object[] { "a", 10 });
table.rows.add(new object[] { "b", 20 });
table.rows.add(new object[] { "c", 40 });
table.rows.add(new object[] { "d", 20 });
table.rows.add(new object[] { "e", 30 });
return table;
}
private void winpieseriesview_load(object sender, eventargs e)
{
builderdevchart();
}
private void builderdevchart()
{
series _pieseries = new series("测试", viewtype.pie);
_pieseries.valuedatamembers[0] = "value";
_pieseries.argumentdatamember = "name";
_pieseries.datasource = createchartdata();
chartcontrol1.series.add(_pieseries);
//----------------------------------------
_pieseries.legendpointoptions.pointview = pointview.argumentandvalues;
_pieseries.setpiepercentage();
}
}
}
/// <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#程序设计有所帮助。