S
Silvers11
Guest
Hello
I have a chart control that contains 2 series in one chartarea:
1. Series1 is of ChartType: Stock
2. Series2 is of ChartType: Line
Adding the Series1 works fine and also Series2. The only problem is that when Series2 (the line) that I want to plot out on the chart is added. The whole "Stock" chart is moved to the right and I don't understand why.
The problem is this function:
void addline(....)
The below code is complete and should work to duplicate the problem by just copy and paste
Thank you!
private void button5_Click(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
double highest = -1; double lowest = 999999999; double high = 0; double low = 0; int periods = 0; Random random = new Random();
for (int i = 0; i < 20; i++)
{
double value = random.Next(160,200);
high = value + 3;
low = value - 3;
chart1.Series["Series1"].Points.AddXY(i.ToString(), low, high, (value -1), (value + 1));
if (high > highest) { highest = high; }
if (low < lowest) { lowest = low; }
periods++;
}
chart1.ChartAreas[0].AxisY.Minimum = lowest;
chart1.ChartAreas[0].AxisY.Maximum = highest;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
//Add line to chart
new Thread(() => addline(chart1, lowest, highest, periods)).Start();
}
void addline(Chart chart, double lowest, double highest, int periods)
{
Thread.Sleep(3000);
Invoke((System.Windows.Forms.MethodInvoker)delegate
{
DataPoint ptstart = new DataPoint(0, 185);
DataPoint ptend = new DataPoint(5, 190);
chart.Series["Series2"].Points.Add(ptstart);
chart.Series["Series2"].Points.Add(ptend);
});
}
Continue reading...
I have a chart control that contains 2 series in one chartarea:
1. Series1 is of ChartType: Stock
2. Series2 is of ChartType: Line
Adding the Series1 works fine and also Series2. The only problem is that when Series2 (the line) that I want to plot out on the chart is added. The whole "Stock" chart is moved to the right and I don't understand why.
The problem is this function:
void addline(....)
The below code is complete and should work to duplicate the problem by just copy and paste
Thank you!
private void button5_Click(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
double highest = -1; double lowest = 999999999; double high = 0; double low = 0; int periods = 0; Random random = new Random();
for (int i = 0; i < 20; i++)
{
double value = random.Next(160,200);
high = value + 3;
low = value - 3;
chart1.Series["Series1"].Points.AddXY(i.ToString(), low, high, (value -1), (value + 1));
if (high > highest) { highest = high; }
if (low < lowest) { lowest = low; }
periods++;
}
chart1.ChartAreas[0].AxisY.Minimum = lowest;
chart1.ChartAreas[0].AxisY.Maximum = highest;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
//Add line to chart
new Thread(() => addline(chart1, lowest, highest, periods)).Start();
}
void addline(Chart chart, double lowest, double highest, int periods)
{
Thread.Sleep(3000);
Invoke((System.Windows.Forms.MethodInvoker)delegate
{
DataPoint ptstart = new DataPoint(0, 185);
DataPoint ptend = new DataPoint(5, 190);
chart.Series["Series2"].Points.Add(ptstart);
chart.Series["Series2"].Points.Add(ptend);
});
}
Continue reading...