Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML WPF wpftoolkit
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.
 
Any one can pls suggest me a solution. Thanks !
 
This is what i have tried :
 
  public List<ram> getRamData()
        {
            List<ram> list = new List<ram>();
            con.Open();
            string query = "select top 1 Used,Total from 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()
                };
                list.Add(reading);
            }
Posted 9-Jan-13 2:12am
Edited 9-Jan-13 3:52am
v2
Comments
Sanjay Debnath at 9-Jan-13 7:28am
   
may be this can help
http://www.codeproject.com/Articles/196502/WPF-Toolkit-Charting-Controls-Line-Bar-Area-Pie-Co
or
http://www.c-sharpcorner.com/uploadfile/mahesh/pie-chart-in-wpf/
BuBa1947 at 9-Jan-13 7:37am
   
Thank you sanjay, I have refereed these links already. But in both links, they have binded the Itemsource from list , not from a database. my question is , how to bind Pie Chart datacontext to a DataBase
Sandeep Mewara at 9-Jan-13 8:26am
   
Just get the data from database as List.. whats the problem?
BuBa1947 at 9-Jan-13 8:52am
   
@Sandeep Mewara: Kindly check my code above. is that the right way ?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello, please take a look over here, it could solve your problem, perhaps :
http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 325
1 Sergey Alexandrovich Kryukov 289
2 CPallini 275
3 DamithSL 260
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100