WPF toolkit 柱状图值显示

wpf 柱状图 默认的图片显示如下,当鼠标落在对应的柱子上的时候,其对应的值才会通过tooltip显示出来,

 

 


 

其代码非常简单,假定我们的数据集合是一个Dictionary<DateTime,double>(我们定义一个成员变量result)的集合。

其xaml代码为

1    < chartingToolkit:Chart  Name = " ColumnChartDefault "  Title = " ChartWithDefaultValue "  LegendTitle = " Chart " >
2               < chartingToolkit:ColumnSeries  Name = " defaultColumnSeries "  Title = " DefaultChart "    IndependentValuePath = " Key "  DependentValuePath = " Value " />
3           </ chartingToolkit:Chart >

 

 在后台将result对象经过数据填充赋给ItemsSource即可。

 

然而,默认的显示方式也有些弊端,以上图为例,在查看统计图标的时候,对于每个柱状的数据不能一目了然的看出,必须将鼠标放在指定的柱状上才能显示,所以有时候需要将各个柱状对应的值默认的显示出来,如下图:

 

其实对于这个修改也很简单,主要是修改xaml中的style,我们知道,默认显示的是因为它通过tooltip来显示(对应线图和饼图都是一样),所以我们可以修改其style,其xaml如下:

 

 1  < chartingToolkit:Chart Grid.Column = " 1 "  Name = " ColumnCharShowValue "  LegendTitle = " Chart "  Title = " ChartShowValue "   >
 2                 < chartingToolkit:ColumnSeries Name = " columnSeriesShowValue "   Title = " ChartShowValue "    IndependentValuePath = " Key "  DependentValuePath = " Value " >
 3                < chartingToolkit:ColumnSeries.DataPointStyle >
 4                    < Style TargetType = " chartingToolkit:ColumnDataPoint " >
 5                         < Setter Property = " Background "  Value = " SkyBlue " />
 6                          < Setter Property = " Template " >
 7                            < Setter.Value >
 8                                  < ControlTemplate TargetType = " chartingToolkit:ColumnDataPoint " >
 9                                    < Grid >
10                                      < Rectangle  Fill = " {TemplateBinding Background} "  Stroke = " Black " />
11                                       < Grid Background = " LightBlue "   Margin = " 0 "  HorizontalAlignment = " Center "  VerticalAlignment = " Top " >
12                                           < TextBlock  Text = " {TemplateBinding FormattedDependentValue} "   FontWeight = " Bold "   Margin = " 0,-20,0,0 "  VerticalAlignment = " Bottom "    HorizontalAlignment = " Center "   />
13                                         </ Grid >
14                                      </ Grid >
15                                  </ ControlTemplate >
16                             </ Setter.Value >
17                         </ Setter >
18                     </ Style >
19         </ chartingToolkit:ColumnSeries.DataPointStyle >
20       </ chartingToolkit:ColumnSeries >
21            </ chartingToolkit:Chart >  
22 

 

  

同样,在后台代码里将result数据填充后赋给其ItemsSource即可。

 

ps:虽然现在看起来很简单,但自己当时在做这的时候还是遇到了很多问题,主要原因是对WPF的熟悉度不够,今天将其贴出来,也是告诉自己很多事情只要自己去静心钻研,看起来很难的东西其实也就那么简单,好好学习,静心学习~

转载于:https://www.cnblogs.com/_Sun_Shine_/archive/2010/11/14/1876805.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值