62,046
社区成员
发帖
与我相关
我的任务
分享
public void pie(double a, double b)
{
this.CT_bingTu.FileManager.FileName = "neware"; //图片名称为neware
/*
* 定义datatable绑定数据,为绘制图片准备数据绑定
*/
DataTable da = new DataTable();
da.Columns.Add("X", typeof(string)); //图形X轴
da.Columns.Add("Y", typeof(int)); //图形Y轴
/*
* 填充tabatable
*/
DataRow dr = da.NewRow();
dr["X"] = "符合条件";
dr["Y"] = a;
da.Rows.Add(dr);
DataRow dr1 = da.NewRow();
dr1["X"] = "落选";
dr1["Y"] = b;
da.Rows.Add(dr1);
/*
* 绑定饼图
*/
ShowData show = new ShowData();
show.Title = "容量统计图"; //图形标题
show.Xtitle = "日期"; //图形X轴说明
show.Ytitle = "单位(个)"; //图形Y轴说明
show.Pichight = 300; //高度
show.Picwidth = 600; //宽度
show.Seriesname = "具体详情"; //详细说明标题
show.Phaysicalimagepath = "ChartImages"; //图片保存相对路径
show.Dt = da; //绑定datatable 数据
show.CreatePie(this.CT_bingTu); //绑定
}
public ShowData() { }
public ShowData(string PhaysicalImagePath, string Title, string XTitle, string YTitle, string SeriesName)
{
_phaysicalimagepath = PhaysicalImagePath;
_title = Title;
_xtitle = XTitle;
_ytitle = YTitle;
_seriesname = SeriesName;
}
private string _phaysicalimagepath;//图片存放路径
public string Phaysicalimagepath
{
get { return _phaysicalimagepath; }
set { _phaysicalimagepath = value; }
}
private string _title; //图片标题
public string Title
{
get { return _title; }
set { _title = value; }
}
private string _xtitle;//图片x座标名称
public string Xtitle
{
get { return _xtitle; }
set { _xtitle = value; }
}
private string _ytitle;//图片y座标名称
public string Ytitle
{
get { return _ytitle; }
set { _ytitle = value; }
}
private string _seriesname;//图例名称
public string Seriesname
{
get { return _seriesname; }
set { _seriesname = value; }
}
private int _picwidth;//图片宽度
public int Picwidth
{
get { return _picwidth; }
set { _picwidth = value; }
}
private int _pichight;//图片高度
public int Pichight
{
get { return _pichight; }
set { _pichight = value; }
}
private DataTable _dt;//图片数据源
public DataTable Dt
{
get { return _dt; }
set { _dt = value; }
}
/// <summary>
/// 饼图
/// </summary>
/// <param name="chart"></param>
public void CreatePie(dotnetCHARTING.Chart chart)
{
chart.Title = this._title;
chart.TempDirectory = this._phaysicalimagepath;
chart.Width = this._picwidth;
chart.Height = this._pichight;
chart.Type = ChartType.Pie;
chart.Series.Type = SeriesType.Cylinder;
chart.Series.Name = this._seriesname;
chart.ShadingEffect = true;
chart.Use3D = false;
chart.DefaultSeries.DefaultElement.Transparency = 20;
chart.DefaultSeries.DefaultElement.ShowValue = true;
chart.PieLabelMode = PieLabelMode.Outside;
chart.SeriesCollection.Add(getArrayData());
chart.Series.DefaultElement.ShowValue = true;
}
private SeriesCollection getArrayData()
{
SeriesCollection SC = new SeriesCollection();
DataTable dt = this._dt;
for (int i = 0; i < dt.Rows.Count; i++)
{
Series s = new Series();
s.Name = dt.Rows[i][0].ToString();
Element e = new Element();
// 每元素的名称
e.Name = dt.Rows[i][0].ToString();
// 每元素的大小数值
e.YValue = Convert.ToInt32(dt.Rows[i][1].ToString());
s.Elements.Add(e);
SC.Add(s);
}
return SC;
}
/**/
/// <summary>
/// 曲线图
/// </summary>
/// <returns></returns>
public void CreateLine(dotnetCHARTING.Chart chart)
{
chart.Title = this._title;
chart.XAxis.Label.Text = this._xtitle;
chart.YAxis.Label.Text = this._ytitle;
chart.TempDirectory = this._phaysicalimagepath;
chart.Width = this._picwidth;
chart.Height = this._pichight;
chart.Type = ChartType.Combo;
chart.Series.Type = SeriesType.Line;
chart.Series.Name = this._seriesname;
chart.Series.Data = this._dt;
chart.SeriesCollection.Add();
chart.DefaultSeries.DefaultElement.ShowValue = true;
chart.ShadingEffect = true;
chart.Use3D = false;
chart.Series.DefaultElement.ShowValue = true;
}
/// <summary>
/// 柱状图
/// </summary>
/// <param name="chart"></param>
public void CreateColumn(dotnetCHARTING.Chart chart)
{
chart.Title = this._title;
chart.XAxis.Label.Text = this._xtitle;
chart.YAxis.Label.Text = this._ytitle;
chart.TempDirectory = this._phaysicalimagepath;
chart.Width = this._picwidth;
chart.Height = this._pichight;
chart.Type = ChartType.Combo;
chart.Series.Type = SeriesType.Cylinder;
chart.Series.Name = this._seriesname;
chart.Series.Data = this._dt;
chart.SeriesCollection.Add();
chart.DefaultSeries.DefaultElement.ShowValue = true;
chart.ShadingEffect = true;
chart.Use3D = false;
chart.Series.DefaultElement.ShowValue = true;
}