【问题标题】:Silverlight Chart QuestionSilverlight 图表问题
【发布时间】:2010-11-11 13:26:47
【问题描述】:

我还没有足够的代表点来发布图像,但是给出了一个使用 ColumnSeries 的 Silverlight 4 图表示例,我如何才能使当前堆叠在彼此顶部的单个列中的每个子列坐在一起旁边?

例如,NVQ2 列显示 5 个不同位置的值列,NVQ3 列显示 5 个不同位置的值列

我需要这些位置并排放置,而不是堆叠在一起。

图表代码:

foreach (ER_Location theLocation in UserSelections.TheDataSet.ER_Locations)
                    {
                        ER_Year myYear = (ER_Year)SeriesSelection.SelectedItem;
                        ColumnSeries newSeries = new ColumnSeries();
                        newSeries.ItemsSource = UserSelections.GetDataRowsByYearAndLocation(theLocation.Location_ID, (int)myYear.Year);
                        newSeries.IndependentValueBinding = new System.Windows.Data.Binding("Variable_ID");
                        newSeries.DependentValueBinding = new System.Windows.Data.Binding("Value");
                        newSeries.Title = theLocation.Name;
                        newSeries.IsSelectionEnabled = true;
                        MainChart.Series.Add(newSeries);
                    }

更新:

这是图表目前的呈现方式:

【问题讨论】:

  • 在提到图表时,您是否使用了通常意义上的“堆叠”一词?通常,图表中的多个列系列会将特定 IndependentValue 的每一列并排放置。您需要使用 StackedColumnSeries 将它们堆叠起来。
  • 如果我今晚可以将我的 Rep 提升到 10,我明天会发布一张图片,直观地解释它!我现在无法发布图片。
  • 添加了当前的渲染方式,也许这可以更好地说明问题。非常感谢。

标签: silverlight silverlight-4.0 charts


【解决方案1】:

我猜你的代码有以下using 声明:-

using System.Windows.Controls.DataVisualization.Charting.Compatible

实际上有两种不同的类型,名称为ColumnSeries。一个在上述命名空间中,它派生自StackedColumnSeries

但是,原始的非堆叠 ColumnSeries 存在于主 Charting 命名空间中。这种类型将并排放置每列。因此,我怀疑您需要做的就是从您的using 中消除多余的.Compatible:-

using System.Windows.Controls.DataVisualization.Charting;

【讨论】:

  • 非常感谢这位 Anthony,现在可以并排显示酒吧。然而,所有的条现在都以相同的颜色显示,而之前它们以不同的颜色显示?有什么明显的我应该做的吗?
【解决方案2】:

您必须创建一个具有颜色属性的类。

例子,

public class MyColor
{
    public Brush ChartColor { get; set; }
}

然后创建一个您喜欢的颜色列表,例如

List<MyColor> colorList = new List<MyColor>
{
    new MyColor
      { ChartColor = new SolidColorBrush(Colors.Blue)},
    new MyColor
      { ChartColor = new SolidColorBrush(Colors.Green) },
    ...
    ...
}

从 Xaml 中,将数据点的背景颜色绑定到 ChartColor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多