MVC框架下的图表使用(二)
这次来说说Area图的设置,还是以书店数据库为例,下面就列出2008年,2009年每个季度的收益对比
效图果如下:
代码如下,对一些属性做了注释,有兴趣的同学可以试试
代码
System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
Chart1.Width = 500;
Chart1.Height = 296;
Chart1.RenderType = RenderType.ImageTag;
Chart1.Palette = ChartColorPalette.BrightPastel;
Chart1.BackGradientStyle = GradientStyle.TopBottom;
//设置2008年的数据
double[] yValues = { 30, 75, 60, 100};
string[] xValues = { "第一季度", "第二季度", "第三季度", "第四季度" };
Series series2008 = new Series();
series2008.Name = "2008";
Chart1.Series.Add(series2008);
Chart1.Series["2008"].Points.DataBindXY(xValues, yValues);
Chart1.Series["2008"].ChartType = SeriesChartType.SplineArea;
Chart1.Series["2008"].IsValueShownAsLabel = true; //是否在图里显示每一项数据
Chart1.Series["2008"].MarkerStyle = MarkerStyle.Circle; //数据项标识图形
Chart1.Series["2008"].MarkerColor = System.Drawing.Color.Azure; //数据项标识颜色
//设置2009年的数据
double[] yValues1 = { 100, 50, 120, 30 };
string[] xValues1 = { "第一季度", "第二季度", "第三季度", "第四季度" };
Series series2009 = new Series();
series2009.Name = "2009";
Chart1.Series.Add(series2009);
Chart1.Series["2009"].Points.DataBindXY(xValues1, yValues1);
Chart1.Series["2009"].ChartType = SeriesChartType.SplineArea;
Chart1.Series["2009"].IsValueShownAsLabel = true;
Chart1.Series["2009"].MarkerStyle = MarkerStyle.Circle;
Chart1.Series["2009"].MarkerColor = System.Drawing.Color.Black;
ChartArea charArea = new ChartArea();
charArea.Name = "ChartArea1";
Chart1.ChartAreas.Add(charArea);
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.ChartAreas["ChartArea1"].ShadowColor = System.Drawing.Color.Transparent;
Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
//将两组数据设置为同一区域
Chart1.Series["2008"].ChartArea = charArea.Name;
Chart1.Series["2009"].ChartArea = charArea.Name;
Legend legend = new Legend();
Chart1.Legends.Add(legend);
// Render chart control
Chart1.Page = this.Parent.Page;
HtmlTextWriter writer = new HtmlTextWriter(this.Parent.Page.Response.Output);
Chart1.RenderControl(writer);
Chart1.Width = 500;
Chart1.Height = 296;
Chart1.RenderType = RenderType.ImageTag;
Chart1.Palette = ChartColorPalette.BrightPastel;
Chart1.BackGradientStyle = GradientStyle.TopBottom;
//设置2008年的数据
double[] yValues = { 30, 75, 60, 100};
string[] xValues = { "第一季度", "第二季度", "第三季度", "第四季度" };
Series series2008 = new Series();
series2008.Name = "2008";
Chart1.Series.Add(series2008);
Chart1.Series["2008"].Points.DataBindXY(xValues, yValues);
Chart1.Series["2008"].ChartType = SeriesChartType.SplineArea;
Chart1.Series["2008"].IsValueShownAsLabel = true; //是否在图里显示每一项数据
Chart1.Series["2008"].MarkerStyle = MarkerStyle.Circle; //数据项标识图形
Chart1.Series["2008"].MarkerColor = System.Drawing.Color.Azure; //数据项标识颜色
//设置2009年的数据
double[] yValues1 = { 100, 50, 120, 30 };
string[] xValues1 = { "第一季度", "第二季度", "第三季度", "第四季度" };
Series series2009 = new Series();
series2009.Name = "2009";
Chart1.Series.Add(series2009);
Chart1.Series["2009"].Points.DataBindXY(xValues1, yValues1);
Chart1.Series["2009"].ChartType = SeriesChartType.SplineArea;
Chart1.Series["2009"].IsValueShownAsLabel = true;
Chart1.Series["2009"].MarkerStyle = MarkerStyle.Circle;
Chart1.Series["2009"].MarkerColor = System.Drawing.Color.Black;
ChartArea charArea = new ChartArea();
charArea.Name = "ChartArea1";
Chart1.ChartAreas.Add(charArea);
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.ChartAreas["ChartArea1"].ShadowColor = System.Drawing.Color.Transparent;
Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
//将两组数据设置为同一区域
Chart1.Series["2008"].ChartArea = charArea.Name;
Chart1.Series["2009"].ChartArea = charArea.Name;
Legend legend = new Legend();
Chart1.Legends.Add(legend);
// Render chart control
Chart1.Page = this.Parent.Page;
HtmlTextWriter writer = new HtmlTextWriter(this.Parent.Page.Response.Output);
Chart1.RenderControl(writer);
好了,下次帖点高级的,关于drilldown功能
posted on 2010-08-17 23:12 我不是冷狐冲,我就是一酒壶 阅读(623) 评论(0) 编辑 收藏 举报