绘制折线图 - 从WCF到Silverlight

时间:2014-04-20 18:05:29

标签: c# wcf silverlight charts

我正在尝试使用Chart控件在silverlight上绘制图表..我从WCF获取数据..我可以从服务中填写一些文本框:

//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"]);

我尝试使用此代码在XAML主页中生成图表,但它不是正确的

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;

我只是C#的新手,正在寻找帮助,产生这个年份显示SQFT的折线图。

1 个答案:

答案 0 :(得分:0)

我使用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 ),

    };