62,272
社区成员
发帖
与我相关
我的任务
分享
private SeriesCollection getChartData(DataTable dt)
{
SeriesCollection SC = new SeriesCollection();
Series s = new Series();
for (int i = 0; i < dt.Rows.Count; i++)
{
Element e = new Element();
e.Name = dt.Rows[i]["x轴的字段,比如月份"].ToString();
e.YValue = Convert.ToDouble(dt.Rows[i]["每个月份对应的数值总和"].ToString());
e.ShowValue = true;
s.Elements.Add(e);
}
SC.Add(s);
return SC;
}
private void DrawDotChart(DataTable dt)
{
Chart1.Title = "统计图标题";
Chart1.Use3D = true ; // 3D效果
Chart1.DefaultSeries.DefaultElement.Transparency = 10;
Chart1.ShadingEffectMode = ShadingEffectMode.Five; // 3d效果的色彩数
Chart1.DefaultSeries.Type = SeriesType.Line; 折线
//Chart1.DefaultSeries.Type = SeriesType.Column; 柱状
// Chart1.DefaultSeries.Type = SeriesType.Spline; 曲线
Chart1.YAxis.Scale = Scale.Normal;
Chart1.XAxis.Label.Text = "x轴标题";
Chart1.YAxis.Label.Text = "y轴标题";
Chart1.TempDirectory = "~/temp"; // 图片路径
Chart1.Width = 860; 宽度
Chart1.Height = 370; 高度
Chart1.FileName = "DaySell"; 图片名称
Chart1.SeriesCollection.Clear();
Chart1.SeriesCollection.Add(getChartData(dt));
}