Skip to main content

ChartControl.RefreshData() Method

Reloads data from the underlying data source and repaints the diagram area.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.UI.dll

NuGet Package: DevExpress.Win.Charts

Declaration

public void RefreshData()

Remarks

If a data source implements the IBindingList, INotifyCollectionChanged or DevExpress.Data.ChartDataSources.IChartDataSource interface, XtraCharts refreshes a chart’s data only when data in the data source has been changed. If the data source does not implement these interfaces, you can manually handle the way in which chart data should be refreshed via the ChartControl.RefreshDataOnRepaint property.

Example

In the following code, a new data point is added to a data source when a user clicks the Add Point button. The Chart Control uses a data source of the List<T> type that does not implement previously mentioned interfaces. For this reason, you should call the RefreshData method to notify the chart about the data source changes and make the chart re-render the diagram area.

using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace ChartExample {
    public partial class Form1 : Form {
        Random rand = new Random();
        List<DataPoint> data;
        public Form1() {
            InitializeComponent();
            data = GetPoints();
        }
        private void Form1_Load(object sender, EventArgs e) {
            Series series = new Series("Series 1", ViewType.Line);
            series.DataSource = data;
            series.ArgumentDataMember = "Argument";
            series.ValueDataMembers.AddRange("Value");
            chartControl1.Series.Add(series);

            XYDiagram diagram = chartControl1.Diagram as XYDiagram;
            diagram.AxisX.DateTimeScaleOptions.ScaleMode = ScaleMode.Continuous;

            LineSeriesView view = (LineSeriesView)series.View;
            view.MarkerVisibility = DevExpress.Utils.DefaultBoolean.True;
        }

        private void OnAddPointButtonClick(object sender, EventArgs e) {
            data.Add(new DataPoint(DateTime.Now, rand.NextDouble() * 50));
            chartControl1.RefreshData();
        }

        public List<DataPoint> GetPoints() {
             return new List<DataPoint> {
                new DataPoint(DateTime.Now.AddSeconds(- 5), 56.1226),
                new DataPoint(DateTime.Now.AddSeconds(- 4), 50.18432),
                new DataPoint(DateTime.Now.AddSeconds(- 3), 51.51443),
                new DataPoint(DateTime.Now.AddSeconds(- 2), 60.2624),
                new DataPoint(DateTime.Now.AddSeconds(- 1), 65.6321)};

        }
        public class DataPoint {
            public DateTime Argument { get; set; }
            public double Value { get; set; }
            public DataPoint(DateTime argument, double value) {
                this.Argument = argument;
                this.Value = value;
            }
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the RefreshData() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also