anyone know how to bind database data witb live charts wpf?

Sep 26 2017 9:55 AM
I have a table named test which has more than one rows data. I want to read it and show it on the live chart. code is shown below using LiveCharts; using LiveCharts.Wpf; using System; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Windows; using static MAS.clsPUB; namespace MAS.Windows { /// /// Interaction logic for Dash.xaml /// public partial class Dash : Window { public SeriesCollection SeriesCollection { get; set; } public string[] Labels { get; set; } //public Func YFormatter { get; set; } public Dash() { InitializeComponent(); LoadData(); } private void LoadData() { double test =0; if (CON.State == ConnectionState.Open) { CON.Close(); } CON.ConnectionString = ConfigurationManager.ConnectionStrings["conDB"].ConnectionString; CON.Open(); CMD = new SqlCommand("select * from tblWeeklyAudit", CON); RDR = CMD.ExecuteReader(); if (RDR.Read()) { test = Convert.ToDouble(RDR["Defects"]); } SeriesCollection = new SeriesCollection { new LineSeries { Values = new ChartValues { test } }, }; Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May" }; //YFormatter = value => value.ToString("C"); ////modifying the series collection will animate and update the chart //SeriesCollection.Add(new LineSeries //{ // Title = "Series 4", // Values = new ChartValues { 5, 3, 2, 4 }, // LineSmoothness = 0, //0: straight lines, 1: really smooth lines // PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"), // PointGeometrySize = 50, // PointForeground = Brushes.Gray //}); ////modifying any series values will also animate and update the chart //SeriesCollection[3].Values.Add(5d); DataContext = this; } } }