简体   繁体   English

在Silverlight工具箱中以编程方式控制Chart

[英]Programmatically controlling Chart in Silverlight toolkit

I want to control the x and y axis of a multi series line charts available in Silverlight toolkit from the C# code. 我想通过C#代码控制Silverlight工具包中可用的多系列折线图的x和y轴。 I am not able to find any appropriate example using google. 我无法使用Google找到任何合适的示例。 Any kind of example or pointers would be appreciated! 任何类型的示例或指针,将不胜感激!

EDIT: 编辑:

This is what I have done so far: 到目前为止,这是我所做的:

<toolkit:Chart Canvas.Left="104" Canvas.Top="18" Name="chartCompare" Title="Compare Series" Height="285" Width="892">
<toolkit:LineSeries
         Title="SP1"
         Name="Series1"/>
</toolkit:Chart>

And in the code behind I am trying this: 在后面的代码中,我正在尝试这样做:

Series1.ItemsSource = ObjectList;

Series1.IndependentValuePath = "Val1";
Series1.DependentValuePath = "Val2";

Where ObjectList is a List of Objects which has val1 and val2 as its property. 其中ObjectList是具有val1和val2作为其属性的对象列表。 But it is throwing an error when I run this in Line "Series1.ItemsSource = ObjectList;" 但是,当我在"Series1.ItemsSource = ObjectList;"行中运行此命令时,它将引发错误"Series1.ItemsSource = ObjectList;" saying "Object reference not set to an instance of an object..". 说“对象引用未设置为对象的实例..”。 I have initialised and set its value just in the line before it. 我已经初始化并在它之前的行中设置了它的值。 Actually I have set this as an item source for a data grid in the line before it and it works fine. 实际上,我已经将它设置为行之前数据网格的项目源,并且工作正常。

i tried your example and i got "out of index" exeption 我尝试了您的示例,但结果“超出索引”

this form is better 这种形式更好

   LineSeries Series1 = new LineSeries();
    Series1.IndependentValuePath = "Val1";
    Series1.DependentValuePath = "Val2";
    Series1.ItemsSource = ObjectList;
    chart.Series.Add(Series1);

I need to add this before using the Series1: 在使用Series1之前,我需要添加以下内容:

//Line to be inserted
LineSeries Series1 = chart.Series[0] as LineSeries;

Series1.IndependentValuePath = "Val1";
Series1.DependentValuePath = "Val2";
Series1.ItemsSource = ObjectList;

Thanks... 谢谢...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM