当在图表上添加数据时,如何在图表上移动x轴网格 [英] How to move x-axis grids on chart whenever a data is added on the chart

查看:143
本文介绍了当在图表上添加数据时,如何在图表上移动x轴网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//网格线不随着线点变化而移动。我应该添加什么代码使它看起来像cpu性能图表?

 系列test1 = new Series 
系列test2 = new Series();

private void Form1_Load(object sender,EventArgs e)
{
test1.Color = Color.Blue;
test1.ChartType = SeriesChartType.FastLine;
test1.BorderWidth = 2;

test2.Color = Color.Red;
test2.ChartType = SeriesChartType.FastLine;
test2.BorderWidth = 2;

chart1.Series.Add(test1);
chart1.Series.Add(test2);

chart1.ChartAreas [0] .AxisX.MajorGrid.Enabled = true;
chart1.ChartAreas [0] .AxisX.IsStartedFromZero = true;
chart1.ChartAreas [0] .AxisX.IntervalOffsetType = DateTimeIntervalType.Number;
}

private void timer1_Tick(object sender,EventArgs e)
{
Axis xaxis = chart1.ChartAreas [0] .AxisX;
xaxis.Minimum = xaxis.Maximum - 10;
Random rnd = new Random();
int dice = rnd.Next(1,7);
float num1 = rnd.Next(1,13);
test1.Points.Add(num1);
test2.Points.Add(dice);
chart1.ResetAutoValues();
}


解决方案

/ p>


  • 您可以从一开始删除最早的DataPoint,从一旦您有多个点数开始。

  • 您可以设置X轴的最小值和最大值,以控制显示的范围。



最终需要做的,如果你添加DataPoints快或长..



您可能还想使用缩放回顾过去。如果您需要保留数据,您仍然可以将删除的点添加到内存列表中,并在需要时将其恢复。


// gridlines are not moving along as the line point changes. what code should I add to make it look like the cpu performance chart?

    Series test1 = new Series();
    Series test2 = new Series();

    private void Form1_Load(object sender, EventArgs e)
    {        
        test1.Color = Color.Blue;
        test1.ChartType = SeriesChartType.FastLine;
        test1.BorderWidth = 2;

        test2.Color = Color.Red;
        test2.ChartType = SeriesChartType.FastLine;
        test2.BorderWidth = 2;

        chart1.Series.Add(test1);
        chart1.Series.Add(test2);

        chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
        chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
        chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number;         
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        Axis xaxis = chart1.ChartAreas[0].AxisX;
        xaxis.Minimum = xaxis.Maximum - 10;
        Random rnd = new Random();
        int dice = rnd.Next(1, 7); 
        float num1 = rnd.Next(1, 13);
        test1.Points.Add(num1);
        test2.Points.Add(dice);
        chart1.ResetAutoValues();
    }

解决方案

You have two options:

  • You can delete the oldest DataPoints from the beginning, starting once you have more than some number of points.
  • You can set a Minimum and Maximum for the X-Axis to control the displayed range.

The former option is what you eventually need to do anyway if you are adding DataPoints fast or long..

You may also want to use zooming to look back into the past. If you need to keep the data, you could still add the removed points into a list in memory and bring them back when needed.

这篇关于当在图表上添加数据时,如何在图表上移动x轴网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆