Silverlight:如何将加载操作的结果绑定到包含很少空值的LineSeries图表

发布于 2024-12-13 10:14:01 字数 1171 浏览 0 评论 0原文

我已将我的图表绑定到加载操作的结果。加载操作返回的结果返回复杂类型,其中某些对象属性的值为 null。

所以我的银光应用程序出现错误。

我的 XAML 代码如下:

<Grid x:Name="LayoutRoot">
        <toolkit:Chart Name="historicalTotalChart" Title="Chart Title">
            <toolkit:LineSeries >

            </toolkit:LineSeries>
        </toolkit:Chart>
    </Grid>

我的 CS 文件中的代码如下:

LoadOperation<GetHistoricalTotalReport_Result> hisTotalsLoadOp =
                context.Load(context.GetHistoricalToalReportQuery(tableName, sD, startDate, endDate));

            LineSeries line = new LineSeries();
            line.ItemsSource = hisTotalsLoadOp.Entities;

            //line.DependentValuePath ="rep_date";
            //line.IndependentValuePath = "expr1";
            line.DependentValueBinding = new Binding("[rep_date]");
            line.IndependentValueBinding = new Binding("[expr1]");
            line.Title = "Historical Totals";
            historicalTotalChart.Series.Add(line);

谁能说一下我该如何克服这个错误?

rep_date、expr1 是我的复杂类型 GetHistoricalTotalReport_Result 中的属性。我是否正确绑定到属性?

非常感谢任何帮助。

谢谢

I have bound a my chart to a result of load operation. The result returned by the load operation returns complex type with values for some of the object's properties is null.

So I am getting an error in my silver light application.

The code of my XAML is as follows:

<Grid x:Name="LayoutRoot">
        <toolkit:Chart Name="historicalTotalChart" Title="Chart Title">
            <toolkit:LineSeries >

            </toolkit:LineSeries>
        </toolkit:Chart>
    </Grid>

Code of in my CS file is as follows:

LoadOperation<GetHistoricalTotalReport_Result> hisTotalsLoadOp =
                context.Load(context.GetHistoricalToalReportQuery(tableName, sD, startDate, endDate));

            LineSeries line = new LineSeries();
            line.ItemsSource = hisTotalsLoadOp.Entities;

            //line.DependentValuePath ="rep_date";
            //line.IndependentValuePath = "expr1";
            line.DependentValueBinding = new Binding("[rep_date]");
            line.IndependentValueBinding = new Binding("[expr1]");
            line.Title = "Historical Totals";
            historicalTotalChart.Series.Add(line);

Can any one say how can I over come this error?

rep_date, expr1 are the properties with in my complex type GetHistoricalTotalReport_Result. I am I binding to the properties correctly?

Any help much appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤城病女 2024-12-20 10:14:01

您的应用程序中可能存在 3 个问题:

  1. 您的绑定不应包含方括号,它们适用于数组和字典。另外,我宁愿使用属性 Dependent/IndependentValuePath,您不应该评论它们,它们是完全正确的。
  2. DependentValuePath 属性必须是数字数据类型,因为它位于 Y 轴上。在您的示例中,rep_date 属性可以是 double 类型。
  3. IndependentValuePath 位于 X 轴上,可以是任何类型,但值不能包含 null。真的,我不知道空值可以在X轴上显示在哪里,这没有意义。

这是正确代码的示例,可以正常工作:

LineSeries line = new LineSeries();
line.ItemsSource = new[]
{
    new ItemViewModel{expr1 = "Item1", rep_date = 25},
    new ItemViewModel{expr1 = "Item2", rep_date = null},
    new ItemViewModel{expr1 = "Item3", rep_date = 31},
    new ItemViewModel{expr1 = "Item4", rep_date = null},
};

line.DependentValuePath = "rep_date";
line.IndependentValuePath = "expr1";
line.Title = "Historical Totals";
historicalTotalChart.Series.Add(line);

下一个代码将不起作用:

line.ItemsSource = new[]
{
    new ItemViewModel{expr1 = null, rep_date = 25} //wrong, x-value can't be null
}

但您可以在显示实体之前过滤它们:

line.ItemsSource = hisTotalsLoadOp.Entities.Where(e => e.expr1 != null).ToList();

There are 3 possible issues in your application:

  1. Your bindings shouldn't contain square brackets, they are for arrays and dictionaries. Also I would rather use the properties Dependent/IndependentValuePath, you shouldn't comment them, they are completely correct.
  2. The DependentValuePath property must be of a numerical data type, because it is situated on the Y-axis. In your example the rep_date property could be of the double type.
  3. The IndependentValuePath is situated on the X-axis and could be of any type but the values can't contain nulls. Really, I have no idea where a null value can be displayed on the X-axis, it doesn't make sense.

Here is the example of the correct code which works fine:

LineSeries line = new LineSeries();
line.ItemsSource = new[]
{
    new ItemViewModel{expr1 = "Item1", rep_date = 25},
    new ItemViewModel{expr1 = "Item2", rep_date = null},
    new ItemViewModel{expr1 = "Item3", rep_date = 31},
    new ItemViewModel{expr1 = "Item4", rep_date = null},
};

line.DependentValuePath = "rep_date";
line.IndependentValuePath = "expr1";
line.Title = "Historical Totals";
historicalTotalChart.Series.Add(line);

The next code will not work:

line.ItemsSource = new[]
{
    new ItemViewModel{expr1 = null, rep_date = 25} //wrong, x-value can't be null
}

But you can filter your entities before displaying them:

line.ItemsSource = hisTotalsLoadOp.Entities.Where(e => e.expr1 != null).ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文