ChartArea1属性设置/// //设置网格的样式 chart1.ChartAreas[ "ChartArea1" ].AxisX.MajorGrid.LineColor = Color.LightGray; chart1.ChartAreas[ "ChartArea1" ].AxisY.MajorGrid.LineColor = Color.LightGray; chart1.ChartAreas[ "ChartArea1" ].AxisX.MajorGrid.IntervalOffset = 1; chart1.ChartAreas[ "ChartArea1" ].AxisY.MajorGrid.IntervalOffset = 0; chart1.ChartAreas[ "ChartArea1" ].AxisX.MajorGrid.Interval = 2; chart1.ChartAreas[ "ChartArea1" ].AxisY.MajorGrid.Interval = 10; chart1.ChartAreas[ "ChartArea1" ].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash; chart1.ChartAreas[ "ChartArea1" ].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.DashDot; //设置坐标轴样式 chart1.ChartAreas[ "ChartArea1" ].AxisX.Title = "随机数" ; chart1.ChartAreas[ "ChartArea1" ].AxisY.Title = "数值" ; chart1.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines; chart1.ChartAreas[0].AxisY.IntervalOffset = 10; chart1.ChartAreas[0].AxisY.Interval = 20; chart1.ChartAreas[0].AxisY.Minimum = -10; //启用3D显示 chart1.ChartAreas[ "ChartArea1" ].Area3DStyle.Enable3D = false ; //设置图表背景 chart1.ChartAreas[0].BackColor = Color.FromArgb(0x87, 0xCC, 0xFF, 0xFF); chart1.ChartAreas[0].BackGradientStyle = GradientStyle.TopBottom; chart1.ChartAreas[0].ShadowColor = Color.Gainsboro; chart1.ChartAreas[0].ShadowOffset = 5; //Series属性设置/// //设置显示类型-线型 chart1.Series[ "随机数" ].ChartType = SeriesChartType.Spline; //设置坐标轴Value显示类型 chart1.Series[ "随机数" ].XValueType = ChartValueType.Int32; //是否显示标签的数值 chart1.Series[ "随机数" ].IsValueShownAsLabel = true ; //设置标记图案 chart1.Series[ "随机数" ].MarkerStyle = MarkerStyle.Circle; chart1.Series[ "随机数" ].MarkerSize = 8; chart1.Series[ "随机数" ].MarkerColor = Color.FromArgb(0x99, 0xFF, 0x00); chart1.Series[ "随机数" ].MarkerBorderColor = Color.Green; chart1.Series[ "随机数" ].MarkerBorderWidth = 2; //设置图案颜色 chart1.Series[ "随机数" ].Color = Color.Green; //设置图案的宽度 chart1.Series[ "随机数" ].BorderWidth = 2; chart1.Series[0].BorderDashStyle = ChartDashStyle.Dash; chart1.Series[0].BorderColor = Color.Red; chart1.Series[0].LabelAngle = 45; chart1.Series[0].LabelBackColor = Color.Aqua; chart1.Series[0].LabelBorderColor = Color.Black; //添加随机数 Random rd = new Random(); for ( int i = 1; i < 20; i++) { //chart1.Series["随机数"].Points.AddXY(i, rd.Next(100)); chart1.Series[ "随机数" ].Points.AddY(rd.Next(100)); } for ( int i = 0; i < chart1.Series[0].Points.Count; i++) { if (chart1.Series[0].Points[i].YValues[0] >= 67.0) chart1.Series[0].Points[i].MarkerBorderColor = Color.DeepPink; else if (chart1.Series[0].Points[i].YValues[0] >= 33.3) chart1.Series[0].Points[i].MarkerBorderColor = Color.DarkOrange; else chart1.Series[0].Points[i].MarkerBorderColor = Color.Gray; } |