I use Chart
to draw a graph with 2 lines. Now my aim is to set the LineColor
of the MajorGrid
of the second Y-axis to the color of the corresponding line. Here is my code:
public partial class Form1 : Form
{
List<double> values_1 = new List<double>();
List<double> values_2 = new List<double>();
public Form1()
{
InitializeComponent();
make_values();
for (int i = 0; i < values_1.Count; i++)
{
chart1.Series[0].Points.AddY(values_1[i]);
}
for (int i = 0; i < values_2.Count; i++)
{
chart1.Series[1].Points.AddY(values_2[i]);
}
// set the colour of grid to corresponding line
chart1.ChartAreas[0].AxisY2.MajorGrid.LineColor = chart1.Series[1].Color;
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void make_values()
{
for (int i = 0; i < 600; i++)
{
values_1.Add(Math.Sin(i / 60.0));
values_2.Add(Math.Cos(i / 60.0));
}
}
}
Since the colours are chosen automatically for the 2 different series I though I could just grab the colour. But when debugging I see that the colour is (0,0,0):
So the grid colour does not change. But the colour of the second series is not (0,0,0) as can be seen when the window is loaded!:
If I force and set manually the colours of the 2 series before that. Everything works fine, and the grid gets the corresponding colour.
Does anyone know at which point in time I would have to grab the colour of the series to get the real value?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…