When the GetValue button is pressed the chart behaves as expected, but when the ClearChart button is pressed the chart clears, but the numbers on the X axis are decimals e.g 1.99999999,2.99999999. It seems the X axis is not being reset as the scroll bar at the bottom does not keep to the right after the chart is cleared. How to I get this chart to clear and start off exactly like it does at the start of the program? here is my code.
int i;
Random rnd = new Random();
private void Chart_Load(object sender, EventArgs e)
{
Chart1.Series.Add("Temp");
Chart1.Series["Temp"].ChartType = SeriesChartType.Spline;
Chart1.Series["Temp"].IsVisibleInLegend = false;
}
private void GetValue_Click(object sender, EventArgs e)
{
Chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoom(0, 20);
Chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.SmallScrollSize = 20;
Chart1.Series["Temp"].Points.AddXY(i, rnd.Next(1, 10));
i++;
Chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position = Chart1.Series["Temp"].Points.Count - Chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size;
}
private void ClearChart_Click(object sender, EventArgs e)
{
Chart1.Series["Temp"].Points.Clear();
}
答案 0 :(得分:2)
Try clearing the points of the chart.
Add the following to the clear handler:
Chart1.Series["Temp"].Points.Clear();
答案 1 :(得分:0)
问题是我没有重置int i,总是简单的事情。