Dharshini

Dharshini

  • NA
  • 24
  • 24.4k

Bind a Pie Chart to a DataSource

Jan 9 2013 9:59 AM

Hello all, 

My goal is to display my database table values ( I have two columns as Total and Used)  on a pie chart. I  used the WPFToolkit for the chart control and created a pie chart structure. But I am stuck with binding the chart to the datasource. 

I have already visited this link, where I found a similar issue with the same concept, but it is for WCF- Silver light :

http://tempuri.org/tempuri.html

any one Kindly help me to proceed pls..

This is what I have done so far :

 class ramTest

    {

        // creating a sql connection string

        SqlConnection con = new SqlConnection("Data Source=TestDB;Initial Catalog=RamDetails;Persist Security Info=True;");

        SqlDataReader dr;

        SqlCommand cmd;

        public List<ram> getRamData()

        {

            List<ram> list = new List<ram>();

            con.Open();

            string query = "select top 1 Used,Total from TestDB.dbo.UsageRam";

            cmd = new SqlCommand(query, con);

            dr = cmd.ExecuteReader();

            while (dr.Read())

            {

               var reading = new ram

                {

               Used = Convert.ToInt32(dr[0]),

               Total = dr[1].ToString() };  // I have a error here because I didn't convert type 'string' to 'float'

                list.Add(reading);

            }

            return list;

        }

        public class ram

        {

            float _total;

            float _used;

            public float Total

            {

                get { return _total; }

                set { _total = value; }

            public float Used

            {

                get { return _used; }

                set { _used = value; }

            }

       }

 }}



Answers (13)