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; }
}
}
}}
Santhosh Kumar JayaramanPosted Jan 10, 2013, 10:42 AM
DharshiniPosted Jan 10, 2013, 10:13 AM
did the Pie chart slice when you builded the project ?
DharshiniPosted Jan 10, 2013, 9:59 AM
Santhosh Kumar JayaramanPosted Jan 10, 2013, 8:50 AM
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.
DharshiniPosted Jan 10, 2013, 6:49 AM
DharshiniPosted Jan 10, 2013, 6:20 AM
Santhosh Kumar JayaramanPosted Jan 10, 2013, 6:01 AM
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?
DharshiniPosted Jan 10, 2013, 5:54 AM
Santhosh Kumar JayaramanPosted Jan 10, 2013, 5:47 AM
DharshiniPosted Jan 10, 2013, 5:45 AM
Santhosh Kumar JayaramanPosted Jan 10, 2013, 5:28 AM
Have you checked this?
http://www.c-sharpcorner.com/uploadfile/mahesh/pie-chart-in-wpf/
DharshiniPosted Jan 10, 2013, 5:09 AM
Vishnujeet KumarPosted Jan 9, 2013, 11:24 PM
http://www.codeproject.com/Articles/28098/A-WPF-Pie-Chart-with-Data-Binding-Support