先来看看效果
公司电力项目需要绘制这种工业图表,之前同事用Series绘制的 有点麻烦 需要计算起始点位置,后来我发现Chart控件本来就提供了这种阴影属性,简单方便
直接上代码
private void InitChart()
{
ChartArea chartArea2 = new ChartArea();
chartArea2.AxisX.Minimum = 10;
chartArea2.AxisX.Maximum = 100;
chartArea2.AxisX.Interval = 10;
chartArea2.AxisX.IsStartedFromZero = true;
chartArea2.AxisX.Title = "主 X 轴";
chartArea2.AxisX.Enabled = AxisEnabled.True;
chartArea2.AxisX.TitleAlignment = StringAlignment.Near;
chartArea2.AxisX.MajorGrid.LineColor = Color.Brown;
chartArea2.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Solid;
chartArea2.AxisY.Minimum = 10;
chartArea2.AxisY.Maximum = 100;
chartArea2.AxisY.Interval = 10;
chartArea2.AxisY.IsStartedFromZero = false;
chartArea2.AxisY.Title = "主 Y 轴";
chartArea2.AxisX.Enabled = AxisEnabled.True;
chartArea2.Name = "chartArea2";
Series m1 = new Series();
m1.Points.AddXY(0, 100);
m1.Points.AddXY(85, 100);
m1.ChartType = SeriesChartType.Area;
m1.Color = Color.Red;
m1.BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
Series m2 = new Series();
m2.Points.AddXY(10, 30);
m2.Points.AddXY(35, 55);
m2.Points.AddXY(65, 55);
m2.Points.AddXY(85, 65);
m2.ChartType = SeriesChartType.Line;
m2.Color = Color.Blue;
m2.BorderWidth = 2;
Series m5 = new Series();
m5.Points.AddXY(10, 30);
m5.Points.AddXY(35, 55);
m5.Points.AddXY(65, 55);
m5.Points.AddXY(85, 65);
m5.ChartType = SeriesChartType.Area;
m5.Color = Color.Purple;
m5.BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
Series m6 = new Series();
m6.Points.AddXY(10, 20);
m6.Points.AddXY(35, 45);
m6.Points.AddXY(65, 45);
m6.Points.AddXY(85, 55);
m6.ChartType = SeriesChartType.Line;
m6.Color = Color.Blue;
m6.BorderWidth = 2;
Series m3 = new Series();
m3.Points.AddXY(10, 20);
m3.Points.AddXY(35, 45);
m3.Points.AddXY(65, 45);
m3.Points.AddXY(85, 55);
m3.ChartType = SeriesChartType.Area;
m3.Color = Color.Green;
m3.BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
this.chart1.Series.Add(m1);
this.chart1.Series.Add(m2);
this.chart1.Series.Add(m5);
this.chart1.Series.Add(m6);
this.chart1.Series.Add(m3);
this.chart1.ChartAreas.Add(chartArea2);
}