This is a migrated thread and some comments may be shown as answers.

[Solved] Databinding to Charts

2 Answers 251 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
gradford
Top achievements
Rank 1
gradford asked on 09 Nov 2009, 05:00 PM
I am creating a dashboard application using the Blacklight DragDockPanel and Telerik's RadControls for Silverlight (specifically RadChart and RadGauge) to display charts, gauges, and data tables. I have a Microsoft Access database that I want to use to bind data to the charts and gauges in my application. I do not have the database hosted, but rather just want to connect to it locally.

Right now my charts and gauges just have random data in them. I am creating all my charts and gauges in C# rather than in XAML. This is how I create my charts:

        public RadChart TD_ReturnSales_Last3Years() //bar 
        { 
            SolidColorBrush us_orange = new SolidColorBrush(); 
            us_orange.Color = Color.FromArgb(255, 236, 117, 61); 
            SolidColorBrush us_green = new SolidColorBrush(); 
            us_green.Color = Color.FromArgb(255, 109, 201, 64); 
            SolidColorBrush us_blue = new SolidColorBrush(); 
            us_blue.Color = Color.FromArgb(255, 0, 159, 194); 
 
            RadChart Chart = new RadChart(); 
 
            Chart.DefaultView.ChartArea.AxisY.Title = "Percent"; 
            Chart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "#Y{%}"; //does not work 
            Chart.DefaultView.ChartArea.AxisY.AutoRange = false; 
            Chart.DefaultView.ChartArea.AxisY.AddRange(0, 15, 3); 
 
            DataSeries dataSeries = new DataSeries(); 
            dataSeries.Definition = new BarSeriesDefinition(); 
            dataSeries.Definition.ShowItemLabels = true; 
            //dataSeries.Definition.ShowItemToolTips = true; 
            dataSeries.Definition.DefaultLabelFormat = "#%"; 
            dataSeries.Definition.Appearance.Fill = us_orange; 
 
            Random random = new Random(this.GetHashCode() | (int)(DateTime.Now.Ticks)); 
            for (int i = 0; i < 3; i++) 
            { 
                DataPoint dataPoint = new DataPoint(); 
                dataPoint.YValue = random.Next(2,12); 
                dataSeries.Add(dataPoint); 
            } 
 
            Chart.DefaultView.ChartArea.DataSeries.Add(dataSeries); 
 
            Chart.DefaultView.ChartArea.AxisX.TickPoints[0].Label = "2006"; 
            Chart.DefaultView.ChartArea.AxisX.TickPoints[1].Label = "2007"; 
            Chart.DefaultView.ChartArea.AxisX.TickPoints[2].Label = "2008"; 
 
 
            Chart.DefaultView.ChartLegend.Visibility = Visibility.Collapsed; 
 
            return Chart; 
        } 
 
 
 


How do I go about setting up this connection and binding the data to my charts? I know that you have to set the DataContext somehow and have looked at all of the examples on the example demo, but I am unsure of how to setup that initial database connection and how to write the queries. 

Any help would be appreciated.

Thank you,
Garrett

2 Answers, 1 is accepted

Sort by
0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 10 Nov 2009, 08:11 AM
Hello Garrett,

I would suggest you to review the databinding help topics in the chart documentation http://www.telerik.com/help/silverlight/data-binding-radchart.html to get you started.


Greetings,
Bart.
0
Grtjn
Top achievements
Rank 1
answered on 26 Feb 2010, 10:20 AM
Hi Garrett,

I am having the same problem to connect to a database (in my case SQL).
How did you solve your problem?

Grtz
Tags
Chart
Asked by
gradford
Top achievements
Rank 1
Answers by
Bartholomeo Rocca
Top achievements
Rank 1
Grtjn
Top achievements
Rank 1
Share this question
or