I currently have a chart on my C# Windows Form Application (in Visual Studio 2013) that gradually draws a line onto it using a timer. I have tried to set the minimum and maximum values for the x- and y-axes and although the y-axis values are being set correctly and appearing as expected on the chart, the x-axis range is not being set correctly and stops at a certain point (around 17.9). Here is the code for the chart and the timer that I currently have:
private void btnPlotGraph_Click(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = double.Parse(txtTotalHorizontalDistance.Text);
chart1.ChartAreas[0].AxisY.Minimum = 0 - double.Parse(txtInitialHeight.Text);
chart1.ChartAreas[0].AxisY.Maximum = double.Parse(txtTotalVerticalDistance.Text);
timer1.Tick += timer1_Tick;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
string[] xCoordinates = File.ReadAllLines("H:\Computing Coursework\Code\FormPrototype\testX.txt");
string[] yCoordinates = File.ReadAllLines("H:\Computing Coursework\Code\FormPrototype\testY.txt");
chart1.Series["Projectile1"].Points.AddXY(xCoordinates[i], yCoordinates[i]);
if (i >= xCoordinates.Length - 1)
{
timer1.Stop();
}
else
{
i++;
}
}
Also, here is a screenshot of the form once it is run to show the problem with the x-axis maximum value (which should be 81.08 as shown in the text box):
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…