PLOTTING SFCHARTS DYNAMICALLY BASED ON SQLITE QUERIES' RESULTS

HI Syncfusion Team,

I am facing a challenge to reach my application objective.

The challenge is I would like to plot a Chart(Let's say a bar graph) based on SQLITE queries, For an example when a button is pressed the SQLITE query will return rows of data where first column is "Date" and second column is for "Price"

Below is the Table in SQLITE Table



Lets say my query will "SUM" the Price and "GROUP" it into Month, screenshot as below:



var stmnt = ("SELECT (BookDate) as BookDate, SUM(Price) as Price FROM Book GROUP BY (BookDate);");
                var dt = conn.Query<Book>(stmnt).ToList();
                dbview.ItemsSource = dt;



The Code above is the one I am currently using to do the queries and then I iterate through the list to access all the values for "Price" and also the "Dates"  

So I would like to plot the SfChart dynamically based on the SQLITE queries, whenever there are new data the query will result more rows.

Please assist or guide on this matter.

Thank you in advance

6 Replies

SM Saravanan Madheswaran Syncfusion Team February 15, 2021 05:51 AM UTC

Hi Jai, 
 
Greetings from Syncfusion support. 
 
Please follow the below guidelines to bind SQLite database to SfChart. And by resetting the series ItemsSource at each query update we can update the chart as well.  
 
 
Please check and let us know the concern.  
 
Regards, 
Saravanan.  



JK Jai kumaran replied to Saravanan Madheswaran February 19, 2021 05:21 AM UTC

Hi Jai, 
 
Greetings from Syncfusion support. 
 
Please follow the below guidelines to bind SQLite database to SfChart. And by resetting the series ItemsSource at each query update we can update the chart as well.  
 
 
Please check and let us know the concern.  
 
Regards, 
Saravanan.  


Hi Mr. Saravanan Thank you for the reply.

I tried to follow your example, but I did not manage to get through it, forgive me as I am really new into this.

In order to make things easier for you to understand what I am trying to achieve. I have attached a link to my google drive where the project solution is located.
Would you help me to check what are the mistakes I am making?

My objective is straight forward. I insert the data into sqlite, then i would like to see the data plotted into the chart.


Thank you
Best regards


JK Jai kumaran replied to Saravanan Madheswaran February 21, 2021 05:30 AM UTC

Hi Jai, 
 
Greetings from Syncfusion support. 
 
Please follow the below guidelines to bind SQLite database to SfChart. And by resetting the series ItemsSource at each query update we can update the chart as well.  
 
 
Please check and let us know the concern.  
 
Regards, 
Saravanan.  


Hi Mr.Saravanan,

I received an email that saying you would need permission to download the file that shared as a link. I did approve the request, did you manage to download it?

Thank you
Best regards


YP Yuvaraj Palanisamy Syncfusion Team February 22, 2021 11:44 AM UTC

Hi Jai Kumaran, 
 
Thanks for providing the sample and permission for the sample to be accessed. 
 
You can resolve the reported problem “Series datapoints not updated properly” with the help of setting ItemsSource property of ChartSeries. Please find the code example below for your reference. 
 
Code Snippet: 
 
ChartViewPage.xaml.cs 
protected override void OnAppearing() 
 { 
     base.OnAppearing(); 
 
     using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH)) 
     { 
         conn.CreateTable<MyClass>(); 
         var s = conn.Table<MyClass>().ToList(); 
         DBView.ItemsSource = s; 
     } 
 } 
 
Also, we have attached the sample for your reference. Please find the sample from the below link. 
 
  
Output: 
 
 
Regards, 
Yuvaraj. 



JK Jai kumaran replied to Yuvaraj Palanisamy February 23, 2021 12:58 AM UTC

Hi Jai Kumaran, 
 
Thanks for providing the sample and permission for the sample to be accessed. 
 
You can resolve the reported problem “Series datapoints not updated properly” with the help of setting ItemsSource property of ChartSeries. Please find the code example below for your reference. 
 
Code Snippet: 
 
ChartViewPage.xaml.cs 
protected override void OnAppearing() 
 { 
     base.OnAppearing(); 
 
     using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH)) 
     { 
         conn.CreateTable<MyClass>(); 
         var s = conn.Table<MyClass>().ToList(); 
         DBView.ItemsSource = s; 
     } 
 } 
 
Also, we have attached the sample for your reference. Please find the sample from the below link. 
 
  
Output: 
 
 
Regards, 
Yuvaraj. 


Hi Mr.Yuvaraj,

Thank you very much for your time to address my mistake and also provide a sample based on my method. Really appreciate it.
Thanks to Mr.Saravanan as well.

Best regards and stay safe


YP Yuvaraj Palanisamy Syncfusion Team February 23, 2021 05:53 AM UTC

Hi Jai kumaran, 
 
Thanks for your update. Please let us know if you have any further assistance. 
 
Regards, 
Yuvaraj

Loader.
Up arrow icon