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
{
List
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; }
}
}
}}

Vishnujeet KumarRank #1,019 · 1.9K reputationPosted Jan 9, 2013, 6:24 PM EST
http://www.codeproject.com/Articles/28098/A-WPF-Pie-Chart-with-Data-Binding-Support
Dharshini24 reputationPosted Jan 10, 2013, 12:09 AM EST
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 10, 2013, 12:28 AM EST
Have you checked this?
http://www.c-sharpcorner.com/uploadfile/mahesh/pie-chart-in-wpf/
Dharshini24 reputationPosted Jan 10, 2013, 12:45 AM EST
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 10, 2013, 12:47 AM EST
Dharshini24 reputationPosted Jan 10, 2013, 12:54 AM EST
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 10, 2013, 1:01 AM EST
PieSeries.ItemsSource = dataTable;
The columns which you want to bind
IndependentValueBinding="{Binding Path=Name}"
DependentValueBinding="{Binding Path=Value}"/>
but i dont understand how to bind two float columns in Pie chart. What it will do?
Dharshini24 reputationPosted Jan 10, 2013, 1:20 AM EST
Dharshini24 reputationPosted Jan 10, 2013, 1:49 AM EST
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 10, 2013, 3:50 AM EST
but i have done binding with datatable, so that you can take it from there. Please check the attached solution.
This is my table structure.
create table test
(id int,
INSERT INTO test VALUES (1,3,9.5)
INSERT INTO test VALUES (2,5.5,7.5)
let me know if you have questions.
Dharshini24 reputationPosted Jan 10, 2013, 4:59 AM EST
Dharshini24 reputationPosted Jan 10, 2013, 5:13 AM EST
did the Pie chart slice when you builded the project ?
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 10, 2013, 5:42 AM EST