WPF工具包(2010年2月发布)图表与柱系列空当的ItemsSource只有一个项目 [英] WPF Toolkit (February 2010 release) Chart with Column Series empty when ItemsSource has only one item

查看:108
本文介绍了WPF工具包(2010年2月发布)图表与柱系列空当的ItemsSource只有一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个恼人的问题:我有一个的ColumnSeries和两个轴(LinearAxis在为相关值,则DateTimeAxis为独立的)一个简单的图表。
我的ColumnSeries'的ItemsSource绑定到数据点的实例的集合(简单的类只有3个属性:日期,IndependentValue和DependentValue)。
图表正确显示的列,如果集合中有2个或更多的项目;的但如果只有有一个后,它不会显示的任何

I'm having an annoying problem: I have a simple Chart with one ColumnSeries and two axis (a LinearAxis for the dependent value and a DateTimeAxis for the independent one). My ColumnSeries' ItemsSource is bound to a Collection of instances of DataPoint (simple class with only 3 properties: Date, IndependentValue and DependentValue). The Chart displays the columns correctly if the Collection has 2 or more items in it; but if it only has one, it won't show any column.

上这是怎么回事任何想法

Any ideas on what's going on?

这里是XAML(与标准和WPF工具包的命名空间不再赘述):

Here's the XAML (with both standard and WPF Toolkit's namespaces omitted for brevity):

<Window x:Class="Demo.MainWindow" (...) xmlns:local="clr-namespace:Demo">
  <Grid>
    <Grid.Resources>
      <local:DataPointCollection x:Key="DataPointCollection" />
    </Grid.Resources>
    <ct:Chart Title="Demo">
      <ct:ColumnSeries Title="A"
                       ItemsSource="{StaticResource DataPointCollection}"
                       IndependentValueBinding="{Binding Date}"
                       DependentValueBinding="{Binding DependentValue}" />
      <ct:Chart.Axes>
        <ct:LinearAxis Orientation="Y"
                       ShowGridLines="True"
                       Title="Dependent Title" />
        <ct:DateTimeAxis Orientation=X"
                         ShowGridLines="True"
                         Interval="1"
                         IntervalType="Days" />
      </ct:Chart.Axes>
    </ct:Chart>
  </Grid>
</Window>



DataPointCollection类:

The DataPointCollection class:

using System;

namespace Demo
{
  using System.Collections.ObjectModel;

  public class DataPointCollection: Collection<DataPoint>
  {
    public DataPointCollection()
    {
      Add(new DataPoint { Date = DateTime.Now.Date, DependentValue = 5 });
      // Comment next line to see an empty chart:
      Add(new DataPoint { Date = DateTime.Now.Date.AddDays(1), DependentValue = 6 });
    }
  }
}

和的dataPoint类:

And the DataPoint class:

using System;

namespace Demo
{
  public class DataPoint
  {
    public DateTime Date { get; set; }
    public double DependentValue { get; set; }
  }
}



该项目是一个普通的WPF应用程序(WPF 4 )。

The project is a regular WPF Application (WPF 4).

先谢谢了。

推荐答案

看了一眼源为的ColumnSeries 代码显示列的宽度是关系到数据的范围,而你的情况是零。除非你想修复bug的工具包,唯一的解决方法我可以建议就是围绕你与哑点单点使它看起来像只有一列正在显示:

Glancing at the source code for ColumnSeries shows that the column width is related to the range of the data, which in your case is zero. Unless you want to fix bugs in the toolkit, the only workaround I can suggest is to surround your single point with dummy points to make it look like only one column is being shown:

        var now = DateTime.Now;
        Add(new DataPoint { Date = now, DependentValue = 5 });
        Add(new DataPoint { Date = now + TimeSpan.FromDays(1), DependentValue = 0 });
        Add(new DataPoint { Date = now - TimeSpan.FromDays(1), DependentValue = 0 });

这篇关于WPF工具包(2010年2月发布)图表与柱系列空当的ItemsSource只有一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆