1个回答
2013-04-14
展开全部
是哪个包下的?using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DevExpress.XtraCharts;
namespace Mysun{
public class ChartHelper
{
///
/// 将表简单绑定到Chart
///
/// 要绑定的数据源
/// 分析项Index
/// chart控件
/// 数据棒图显示显示的样式,如:StackedBarSeriesView
public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView,string[] seriesToBeDeleted)
{
try
{
chart.DataSource = null;
chart.Series.Clear();
DataTable dtV = HTable2VTable(dataTable, sectionColumn);
if (seriesToBeDeleted != null && seriesToBeDeleted.Length > 0)
foreach (string series in seriesToBeDeleted)
RemoveSeries(dtV, 1, series);
// 设置数据源
chart.DataSource = dtV;
//设置纵坐标项目(分析项)
chart.SeriesDataMember = "Y";
//设置横坐标项目
chart.SeriesTemplate.ArgumentDataMember = "X";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "V" });
//样式
chart.SeriesTemplate.View = seriesView;
foreach (Series s in chart.Series)
s.Label.Visible = false;
}
catch
{
System.Windows.Forms.MessageBox.Show("Chart转换出错");
}
}
public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView)
{
EasyBound(dataTable, sectionColumn, chart, seriesView, null);
}
///
/// 将表绑定到Chart,对指定列给出第二坐标
///
/// 要绑定的数据源
/// 分析项Index
/// chart控件
/// 第一坐标上的数据棒图显示的样式,如:StackedBarSeriesView
/// 第二坐标上的数据显示的样式,如:线图
/// 需要以第二坐标为纵轴的序列名
///第二坐标最大值
public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView, ViewType viewType, string[] lineNames, double maxValue)
{
EasyBound(dataTable, sectionColumn, chart, seriesView, viewType, lineNames, maxValue, null);
} public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView, ViewType viewType, string[] lineNames, double maxValue, string[] seriesToBeDeleted)
{
try
{
EasyBound(dataTable, sectionColumn, chart, seriesView, seriesToBeDeleted);
XYDiagram diagram = (XYDiagram)chart.Diagram;
diagram.SecondaryAxesY.Clear(); SecondaryAxisY axisY = new SecondaryAxisY("axisY");
//axisY.Title.Visible = true;
//设置百分比样式
if (maxValue < 1)
{
axisY.NumericOptions.Format = NumericFormat.Percent;
} //axisY.Range.SetMinMaxValues(0, maxValue);
diagram.SecondaryAxesY.Add(axisY);
foreach (Series series in chart.Series)
{
foreach (string lineName in lineNames)
{
if (lineName == series.Name)
{
series.ChangeView(viewType);
((XYDiagramSeriesViewBase)series.View).AxisY = axisY;
} }
}
}
catch
{
System.Windows.Forms.MessageBox.Show("Chart转换出错");
}
} ///
/// 横表转换为绑定到Chart时候所用的纵表
///
/// 数据源
/// 分析项Index
/// 输出的纵表,字段为X:表示横轴,Y:要分析的各项,V:值
private static DataTable HTable2VTable(DataTable dataTable, int SectionColumn)
{
DataTable dt = new DataTable();
dt.Columns.Add("X", typeof(String));
dt.Columns.Add("Y", typeof(String));
dt.Columns.Add("V", typeof(Double));
foreach (DataRow dr in dataTable.Rows)
{ foreach (DataColumn dc in dataTable.Columns)
{
if (dataTable.Columns[SectionColumn] != dc)
dt.Rows.Add(new object[] {
dc.ColumnName,
dr[SectionColumn],
double.Parse(dr[dc].ToString())
});
}
}
return dt;
} private static void RemoveSeries(DataTable dataTable, int sectionColumn,string name)
{
for (; ; )
{
DataRow[] drs = dataTable.Select("Y = '" + name + "'");
if (drs.Length > 0)
drs[0].Delete();
else
break;
}
} }
}参照我的博客:
http://hi.baidu.com/hujin19861102/blog/item/f15a194e3c1514f5d72afcaf.html
using System.Collections.Generic;
using System.Text;
using System.Data;
using DevExpress.XtraCharts;
namespace Mysun{
public class ChartHelper
{
///
/// 将表简单绑定到Chart
///
/// 要绑定的数据源
/// 分析项Index
/// chart控件
/// 数据棒图显示显示的样式,如:StackedBarSeriesView
public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView,string[] seriesToBeDeleted)
{
try
{
chart.DataSource = null;
chart.Series.Clear();
DataTable dtV = HTable2VTable(dataTable, sectionColumn);
if (seriesToBeDeleted != null && seriesToBeDeleted.Length > 0)
foreach (string series in seriesToBeDeleted)
RemoveSeries(dtV, 1, series);
// 设置数据源
chart.DataSource = dtV;
//设置纵坐标项目(分析项)
chart.SeriesDataMember = "Y";
//设置横坐标项目
chart.SeriesTemplate.ArgumentDataMember = "X";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "V" });
//样式
chart.SeriesTemplate.View = seriesView;
foreach (Series s in chart.Series)
s.Label.Visible = false;
}
catch
{
System.Windows.Forms.MessageBox.Show("Chart转换出错");
}
}
public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView)
{
EasyBound(dataTable, sectionColumn, chart, seriesView, null);
}
///
/// 将表绑定到Chart,对指定列给出第二坐标
///
/// 要绑定的数据源
/// 分析项Index
/// chart控件
/// 第一坐标上的数据棒图显示的样式,如:StackedBarSeriesView
/// 第二坐标上的数据显示的样式,如:线图
/// 需要以第二坐标为纵轴的序列名
///第二坐标最大值
public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView, ViewType viewType, string[] lineNames, double maxValue)
{
EasyBound(dataTable, sectionColumn, chart, seriesView, viewType, lineNames, maxValue, null);
} public static void EasyBound(DataTable dataTable, int sectionColumn, ChartControl chart, BarSeriesView seriesView, ViewType viewType, string[] lineNames, double maxValue, string[] seriesToBeDeleted)
{
try
{
EasyBound(dataTable, sectionColumn, chart, seriesView, seriesToBeDeleted);
XYDiagram diagram = (XYDiagram)chart.Diagram;
diagram.SecondaryAxesY.Clear(); SecondaryAxisY axisY = new SecondaryAxisY("axisY");
//axisY.Title.Visible = true;
//设置百分比样式
if (maxValue < 1)
{
axisY.NumericOptions.Format = NumericFormat.Percent;
} //axisY.Range.SetMinMaxValues(0, maxValue);
diagram.SecondaryAxesY.Add(axisY);
foreach (Series series in chart.Series)
{
foreach (string lineName in lineNames)
{
if (lineName == series.Name)
{
series.ChangeView(viewType);
((XYDiagramSeriesViewBase)series.View).AxisY = axisY;
} }
}
}
catch
{
System.Windows.Forms.MessageBox.Show("Chart转换出错");
}
} ///
/// 横表转换为绑定到Chart时候所用的纵表
///
/// 数据源
/// 分析项Index
/// 输出的纵表,字段为X:表示横轴,Y:要分析的各项,V:值
private static DataTable HTable2VTable(DataTable dataTable, int SectionColumn)
{
DataTable dt = new DataTable();
dt.Columns.Add("X", typeof(String));
dt.Columns.Add("Y", typeof(String));
dt.Columns.Add("V", typeof(Double));
foreach (DataRow dr in dataTable.Rows)
{ foreach (DataColumn dc in dataTable.Columns)
{
if (dataTable.Columns[SectionColumn] != dc)
dt.Rows.Add(new object[] {
dc.ColumnName,
dr[SectionColumn],
double.Parse(dr[dc].ToString())
});
}
}
return dt;
} private static void RemoveSeries(DataTable dataTable, int sectionColumn,string name)
{
for (; ; )
{
DataRow[] drs = dataTable.Select("Y = '" + name + "'");
if (drs.Length > 0)
drs[0].Delete();
else
break;
}
} }
}参照我的博客:
http://hi.baidu.com/hujin19861102/blog/item/f15a194e3c1514f5d72afcaf.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询