Question

I am trying to draw a chart on silverlight using Chart control.. I am getting the data from WCF.. I am able to fill some text box from the service:

//following to be used in chart
                        masterDraft.SQFT09 = Convert.ToDouble(reader["SQFT09"]);
                        masterDraft.SQFT10 = Convert.ToDouble(reader["SQFT10"]);
                        masterDraft.SQFT11 = Convert.ToDouble(reader["SQFT11"]);
                        masterDraft.SQFT12 = Convert.ToDouble(reader["SQFT12"]);
                        masterDraft.SQFT13 = Convert.ToDouble(reader["SQFT13"]);

I tried this code to generate the chart in XAML mainpage, but its not a correct one

private void LoadLineChartData()
     {

         {
            // ChartBorder.Visibility = System.Windows.Visibility.Visible;

             Chart1.BorderThickness = new Thickness(1);
             var b1 = new LineSeries();
             b1.Name = "SQFT";
             b1.Title = "SQFT";
             b1.IsSelectionEnabled = true;
             b1.ItemsSource = masterDraft;
             b1.IndependentValueBinding = new Binding("Year");

             b1.DependentValueBinding = new Binding("SQFT");
             Chart1.Series.Add(b1);
             Chart1.Visibility = System.Windows.Visibility.Visible;

I am just newbie to C#, looking for help generating this line chart showing SQFT along the years.

Was it helpful?

Solution

I solve the problem using keyValuePair.

 ((LineSeries)Chart1.Series[0]).ItemsSource =

   new KeyValuePair<string, double>[]{

        new KeyValuePair<string, double>("09", masterDraft.SQFT09 ),

         new KeyValuePair<string, double>("10", masterDraft.SQFT10 ),
         // new KeyValuePair<string, double>("SQFT10", masterDraft. ),
           new KeyValuePair<string, double>("11", masterDraft.SQFT11 ),
           new KeyValuePair<string, double>("12", masterDraft.SQFT12 ),
             new KeyValuePair<string, double>("13", masterDraft.SQFT13 ),

    };   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top