【发布时间】:2014-06-10 09:18:23
【问题描述】:
我正在为每周统计数据的可视化创建图表。这意味着我需要一个 7 列图表,如果数据不可用,请在相应列上留一个空白区域。 我遇到了很多麻烦,因为我还没有找到合适的 WPF 图表指南(如果你有任何可以随意分享)
这是我的图表:
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
<charting:Chart Name="LastWeekChart" Grid.Row="0" Width="895" Height ="250" HorizontalAlignment="Center" >
<charting:Chart.LegendStyle>
<Style TargetType="datavis:Legend">
<Setter Property="Width" Value="0" />
</Style>
</charting:Chart.LegendStyle>
<charting:ColumnSeries DependentValuePath="Value" IndependentValuePath="Name" ItemsSource="{Binding}" />
</charting:Chart>
这是背后的代码:
public static List<SingleBar> LastWeek = new List<SingleBar>();
class SingleBar
{
public string Name { get; set; }
public double Value { get; set; }
public SingleBar()
{
this.Name = "";
this.Value = 0;
}
public SingleBar(string name, double value)
{
this.Name = name;
this.Value = value;
}
}
如果缺少数据,这就是我填充图表的方式:
if (LastWeek.Count() < 7)
for (int i = LastWeek.Count(); i < 7; i++)
LastWeek.Insert(0, new SingleBar());
所以如果少于7个数据,它会在开头插入空数据。 现在我看到在代码上添加了条,但在图表上只显示一个空条,无论我添加了多少个空条。谁能帮帮我?
编辑:要重现它,请尝试以下操作:
LastWeek.Add(new SingleBar());
LastWeek.Add(new SingleBar());
LastWeek.Add(new SingleBar());
LastWeek.Add(new SingleBar());
LastWeek.Add(new SingleBar("Friday",50));
LastWeek.Add(new SingleBar("Saturday", 75));
LastWeek.Add(new SingleBar("Sunday",60));
LastWeekChart.DataContext = LastWeek;
【问题讨论】:
-
您的问题无法从您的代码中重现。
-
我从外部设备读取日志,因此您无法重现它。试试我现在添加的代码,它创建了相同的条件。
标签: wpf charts wpftoolkit