ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Real time data and smooth scrolling
Posted by Todd on Jul-20-2011 01:56
I am trying to create a real time scrolling window, similar to the example in the NetWinCharts sample.  Instead of dates for the X axis, I'm using doubles.

The problem is, my graph is very jumpy.  The X axis wants to round to the nearest 5 or 10 or 20 mark, which causes it to lurch as it adds data points.

The sample provided is very smooth and the graph lines are always flush with the edges of the graph.  I can't figure out what is different in my code that is causing this.

Any help would be appreciated.  The code is included below.

Todd

    public partial class Form1 : Form
    {
        Random r = new Random();

        public Form1()
        {
            InitializeComponent();

            InitializeRealTimeData();
            DrawChart();
            timer1.Enabled = true;
        }

        public const double point_count = 100;
        public double start_x = -point_count;
        public double next_y = 50.0;
        List<double> data = new List<double>();

        private void InitializeRealTimeData()
        {
            data.Clear();
            for (int i = 0; i < point_count; i++)
                data.Add(double.NaN);
        }

        private void UpdateRealtimeData()
        {
            data.Add(next_y);
            next_y += (r.Next(10) / 10.0 - 0.45);

            if (data.Count > point_count)
            {
                data.RemoveAt(0);
                start_x++;
            }
        }

        private void DrawChart()
        {
            Size new_control_size = winChartViewer1.Size;

            int chart_height = new_control_size.Height;
            int chart_width = new_control_size.Width;

            ChartDirector.XYChart chart = new ChartDirector.XYChart(chart_width, chart_height);

            chart.setPlotArea(45, 35, chart_width - 80, chart_height - 70, -1, -1, -1, -1, -1);
            chart.setClipping();

            chart.xAxis().setLinearScale(start_x, start_x + point_count);

            ChartDirector.LineLayer layer = chart.addLineLayer2();

            layer.addDataSet(data.ToArray(), 0x0000ff, "Apples");

            List<double> xData = new List<double>();
            for (int i = 0; i < data.Count; i++)
                xData.Add(i + (int)start_x);

            layer.setXData(xData.ToArray());

            winChartViewer1.Chart = chart;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            UpdateRealtimeData();
            DrawChart();
        }

        private void startStop_Click(object sender, EventArgs e)
        {
            timer1.Enabled = !timer1.Enabled;
        }
    }

  Re: Real time data and smooth scrolling
Posted by Peter Kwan on Jul-20-2011 03:44
Hi Todd,

The issue you see is probably caused by axis rounding. By default, ChartDirector will make sure the axis starts and ends at a "tick" position. (For example, instead of an axis range of 83.4498 to 115.982, ChartDirector may choose 80 to 120, assuming there is a tick every 10 units.)

If the above is the cause of the problem, disabling axis rounding should solve the problem:

c.xAxis().setRounding(false, false);

Hope this can help.

Regards
Peter Kwan