We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind data table in the SfChart?

Description:

The DataTable type can be bound to the ItemsSource property in ChartSeries.

 

Solution:

The following code example illustrates how to bind the data tables in ChartSeries.

 

XAML

 

 C#

 

 

Figure 1: ColumnSeries renders based on data table fields.

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
5515 10/27/2015 03/13/2018 WPF SfChart 4.5.1 12.4.0.24
Did you find this information helpful?
Comments
skanoko siame Aug 23, 2018

So after linking the database to the chart, how do you go about loading data from the database in real or quick time?

Reply
Muneesh Kumar G [Syncfusion] Aug 24, 2018

Hi Skanoko siame,

 

We have analyzed your requirement and you can achieve this by changing the DataTable collection, which is bind to series ItemsSource as per the below code snippet.

 

Code snippet [C#]:

DispatcherTimer timer = new DispatcherTimer();

        DataViewModel viewModel = new DataViewModel();

        Random rd = new Random();

        string[] names;

        public MainWindow()

        {

            InitializeComponent();

 

            series.ItemsSource = viewModel.Data;

 

            names = new string[] { "Chang", "Ikura", "Kobe", "Peas", "Pepper" };

            timer.Start();

            timer.Tick += timer_Tick;

            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);

        }

      

        void timer_Tick(object sender, EventArgs e)

        {

            viewModel.Data.Rows.RemoveAt(0);

            viewModel.Data.Rows.Add(new Object[] { names[rd.Next(0,4)], rd.Next(4,20) });

        }

 

We have prepared a sample based on this, please find the sample from the following location.

 

Sample: http://www.syncfusion.com/downloads/support/forum/134727/ze/SfChart_DataTable1269039968.zip

 

Hope this helps.

 

Regards,

Muneesh Kumar G.


Reply
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon