View Code
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!IsPostBack) 4 { 5 int[] date = new int[] { 20, 40, 50, 80, 30, 10, 60 }; 6 int[] test = new int[] { 10, 80, 70, 40, 20, 50, 90 }; 7 Chart1.Width = 600; 8 Chart1.Height = 400; 9 Chart1.BackColor = Color.Azure; 10 //设置第一个图表集合 11 Series series = new Series("test"); 12 //设置图表类型 13 //series.ChartType = SeriesChartType.Column;//柱状图 14 15 series.ChartType = SeriesChartType.Line; 16 //设置图表数据点的宽度 17 series.BorderWidth = 1; 18 //设置图表阴影偏移量 19 series.ShadowOffset = 8; 20 //设置数据点颜色 21 series.Color = Color.Red; 22 //指示是否在标签上显示数据点的值 23 // series.IsValueShownAsLabel = false;//不显示数据点 24 series.IsValueShownAsLabel = true; 25 //指示是否显示图例 26 series.IsVisibleInLegend = true; 27 //设置标记样式 28 series.MarkerStyle = MarkerStyle.Diamond; 29 //设置标记大小 30 series.MarkerSize = 3; 31 //设置标记颜色 32 series.MarkerColor = Color.Red; 33 DateTime date1 = DateTime.Now.Date; 34 for (int i = 0; i < date.Length; i++) 35 { 36 series.Points.AddXY(date1, date[i]); 37 series.ToolTip = "日期:\t#VALX\n数值:\t#VALY"; 38 date1 = date1.AddDays(1); 39 } 40 Chart1.Series.Add(series); 41 //创建第二个图标集合 42 Series series1 = new Series(); 43 series1.ChartType = SeriesChartType.Column;//柱状图 44 series1.BorderWidth = 1; 45 series1.Color = Color.Green; 46 series1.ShadowOffset = 1; 47 series1.IsValueShownAsLabel = false; 48 series1.IsVisibleInLegend = true; 49 series1.MarkerStyle = MarkerStyle.Square; 50 series1.MarkerSize = 3; 51 series1.MarkerColor = Color.Black; 52 date1 = DateTime.Now.Date; 53 for (int i = 0; i < test.Length; i++) 54 { 55 series1.Points.AddXY(date1, test[i]); 56 date1 = date1.AddDays(1); 57 series1.ToolTip = "日期:\t#VALX\n数值:\t#VALY"; 58 } 59 Chart1.Series.Add(series1); 60 //设置X轴与Y轴的轴线颜色 61 this.Chart1.ChartAreas[0].AxisX.LineColor = Color.Blue; 62 this.Chart1.ChartAreas[0].AxisY.LineColor = Color.Blue; 63 //设置X轴与Y轴的轴线宽度 64 this.Chart1.ChartAreas[0].AxisY.LineWidth = 2; 65 this.Chart1.ChartAreas[0].AxisX.LineWidth = 2; 66 //设置X轴与Y轴的标题 67 this.Chart1.ChartAreas[0].AxisX.Title = "日期"; 68 this.Chart1.ChartAreas[0].AxisY.Title = "数据"; 69 //设置X轴与Y轴的网格线 70 this.Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Blue; 71 this.Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray; 72 } 73 }
怀揣着一点点梦想的年轻人
相信技术和创新的力量
喜欢快速反应的工作节奏
相信技术和创新的力量
喜欢快速反应的工作节奏