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. Image for the cookie policy date
close icon

Databse Connectivity in Live chart

Hi

I am exploring your Live Chart tool and I want to bind my data in live chart through the database, please help me how to achieve this.

Thanks

3 Replies

JA Jayavigneshwaran Syncfusion Team replied to Ramesh December 5, 2014 09:38 AM UTC

Hi

I am exploring your Live Chart tool and I want to bind my data in live chart through the database, please help me how to achieve this.

Thanks

Hi Ramesh,

Thanks for using Syncfusion product.

We have analyzed your query.

And we made a sample which is updating lively with the data from the data source.

Find the sample from the below specified link.

Link: http://www.syncfusion.com/downloads/support/directtrac/132770/WebApplication1754256877.zip

 

Please let us know if you have any concern.

 

Thanks,

Jayavigneshwaran



RA Ramesh December 8, 2014 12:41 PM UTC

Hi

As I mentioned before my requirements, but your sample is not retrieve data from database, its selecting data randomly. Please provide a sample as per requirements

Thanks


JA Jayavigneshwaran Syncfusion Team replied to Ramesh December 9, 2014 03:22 AM UTC

Hi

As I mentioned before my requirements, but your sample is not retrieve data from database, its selecting data randomly. Please provide a sample as per requirements

Thanks

Hi Ramesh,

Sorry for the inconvenience caused.

 

We have modified the sample to take data from SQL data source and to render chart.

Hereby I have listed the steps to achieve this.


1.       Keep the mdf data source file locally in project. I have kept northwind.mdb file in app data folder.

2.       Create SQL data source element in ASP

[ASPX]

<asp:SqlDataSource ID="SqlData" runat="server" ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"

            SelectCommand="SELECT * FROM [Products] WHERE UnitPrice < 10"></asp:SqlDataSource>

 

3.       Add connection string in web.config file

[web.config]

        <add name="SQLConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True"

   providerName="System.Data.SqlClient" />

4.       Code required to get the data of the data source and convert it to serialize string

[CS]

            var dv = new DataView();

            var dt = new DataTable();

            dv = SqlData.Select(DataSourceSelectArguments.Empty) as DataView;

            dt = dv.ToTable();  // data is get as data table

           

            foreach (DataRow dr in dt.Rows)

            {

                row = new Dictionary<string, object>();

                foreach (DataColumn col in dt.Columns)

                {

                    row.Add(col.ColumnName, dr[col]);

                }

                rows.Add(row); // converted to data column

            }

            a = serializer.Serialize(rows); // serialized to string

            Page.DataBind();

 

5.       Define a hidden element in aspx page and page the string to this elements text

[ASPX]

                       <%--a hidden field to get the value from code behind--%>

            <asp:Label ID="Label1" Text='<%#a%>' runat="server"/>

 

6.       Get the text value in aspx page and parse it to JSON object.

[JS]

           var a = $("#MainContent_Label1").text(); // get the value from the element

                var chartdata = JSON.parse(a);  // parse it to json values

7.       Bind it to chart and make require coding to render a live chart.

 

We have also made a sample to illustrate this. Find it from the below link.

Link: http://www.syncfusion.com/downloads/support/directtrac/132020/WebApplication12126491657.zip

 

Sample is coded in chart.aspx page. Kindly set chart.aspx as start page.

 

Please let us know if you have any concern.

 

Thanks,

Jayavigneshwaran


Loader.
Live Chat Icon For mobile
Up arrow icon