Databinding to Charts

3 posts, 0 answers
  1. gradford
    gradford avatar
    7 posts
    Member since:
    Nov 2009

    Posted 09 Nov 2009 Link to this post

    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); 
                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,
  2. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 10 Nov 2009 Link to this post

    Hello Garrett,

    I would suggest you to review the databinding help topics in the chart documentation to get you started.

  3. Grtjn
    Grtjn avatar
    129 posts
    Member since:
    Feb 2010

    Posted 26 Feb 2010 Link to this post

    Hi Garrett,

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

Back to Top