/要引用2个dll(.NETFramework\v4.0\Microsoft.CSharp.dll;.NETFramework\v4.0\System.Web.DataVisualization.dll)
Chart Chart1 = new Chart();
Color[] color = { Color.Firebrick, Color.Gold, Color.DodgerBlue, Color.OliveDrab, Color.RosyBrown, Color.Coral, Color.HotPink, Color.Goldenrod, Color.NavajoWhite, Color.IndianRed, Color.LawnGreen, Color.MediumPurple, Color.Gray, Color.Orange, Color.Chartreuse };
Chart1.RenderType = RenderType.ImageMap;
Chart1.ImageLocation = "";//保存图片的路径
Chart1.Palette = ChartColorPalette.BrightPastel;//控件的调色板
Title t = new Title("标题", Docking.Top, new System.Drawing.Font("Trebuchet MS", 14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(26, 59, 105));
Chart1.Titles.Add(t);
Chart1.ChartAreas.Add("Series 1");
Chart1.ChartAreas["Series 1"].Area3DStyle.Enable3D = true;
Chart1.ChartAreas["Series 1"].AxisY.Title = "分数";
Chart1.ChartAreas["Series 1"].AxisY.Maximum = 10;
Chart1.ChartAreas["Series 1"].AxisY.Interval = 1;
Chart1.ChartAreas["Series 1"].BackColor = Color.Honeydew;
Chart1.Width = 800;
Chart1.Height = 400;
string MessageChannel = "右侧显示标题";
Chart1.Series.Add(MessageChannel);
Series series = Chart1.Series[MessageChannel];
series.MarkerStep = 1;
series["DrawingStyle"] = "LightToDark";
series["PointWidth"] = "0.5";
DataPoint dp;
//foreach (var m in "ss")
{
dp = new DataPoint();
dp.SetValueXY("X轴", "Y轴");
dp.Color = color[1];//每个颜色
series.Points.Add(dp);
}
series.IsValueShownAsLabel = true;
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart1.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
Chart1.BorderWidth = 2;
Chart1.Legends.Add("Legend1");
// show legend based on check box value
Chart1.Legends["Legend1"].Enabled = true;
//Chart1.RenderControl(writer);
Chart1.SaveImage(Page.MapPath(Chart1.ImageLocation));