开发者

Binding Dictionary to WPF toolkit Chart

Here is my code for binding a dictionary item to a Chart control. I keep getting the following error:

"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

Here is my Code:

foreach (DataRow drow in objD0s.Tables[0].Rows)// Adding values from a dataset to dictionary    
     {


         string strvalue = Convert.ToString(drow["Chemical Name"]);
         string doublevalue = Convert.ToString(drow["Global Warming"]);
         Cdata.Add(Convert.ToString(strvalue), Convert.ToDouble(doublevalue));

     }
     ColumnSeries colSeries = ChartChemImpact.Series[0] as ColumnSeries;     

         ((ColumnSeries)ChartChemImpact.Series[0]).DataContext = Cdata;
         colSeries.ItemsSource = myDataTable0.DefaultView;
         colSeries.IndependentValueBinding = new Binding("[Chemical Name]");
         colSeries.DependentValueBinding = new Binding("[Global Warming]");

  }

XAM

 charting开发者_StackOverflow社区Toolkit:Chart Name="ChartChemImpact" Title="Chart Title"   Width="384"            Height="280">
   <chartingToolkit:ColumnSeries DependentValuePath="Key"  IndependentValuePath="Value" ItemsSource="{Binding}" Name="colSeries" />
  </chartingToolkit:Chart>

Please help :(


Ok, I have found the mistake. There are binding and value paths in the xaml, but they are replaced in the code.

I would remove those lines, so here is the result:

foreach (DataRow drow in objD0s.Tables[0].Rows)// Adding values from a dataset to dictionary    
{
     string strvalue = Convert.ToString(drow["Chemical Name"]);
     string doublevalue = Convert.ToString(drow["Global Warming"]);
     Cdata.Add(Convert.ToString(strvalue), Convert.ToDouble(doublevalue));
}

((ColumnSeries)ChartChemImpact.Series[0]).DataContext = Cdata;
//And that's the end of the function, no more code
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜