Visual Studio 2010 Chart control - line color

2020-07-14 12:18发布

问题:

How do I change the color of the horizonal and vertical lines? I'd like to make them a little lighter, yet leave the X and Y axis black, probably.

Edited:

indyfromoz suggestion resulted in this:

The effect I want is this:

(Subtler horiz and vertical lines, maybe even no vertical lines.)

回答1:

VB

Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.FromArgb(&H50, &H9C, &H9A, &H95)
Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.FromArgb(&H50, &H9C, &H9A, &H95)

C#

Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(50, 200, 200, 200);
Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(50, 200, 200, 200);


回答2:

You have two options - use the Axis.IsInterlaced property or the Axis.StripLines property. This page is a handy reference for customization of the grid lines in a chart.

Here is some sample C# code (from the above reference) -

chart1.ChartAreas[0].AxisY.StripLines.Add(new StripLine()); 
chart1.ChartAreas[0].AxisY.StripLines[0].BackColor = Color.FromArgb(80, 252, 180, 65); 
chart1.ChartAreas[0].AxisY.StripLines[0].StripWidth = 40; 
chart1.ChartAreas[0].AxisY.StripLines[0].Interval = 10000; 
chart1.ChartAreas[0].AxisY.StripLines[0].IntervalOffset **

HTH, indyfromoz