想用wpf做StackedColumnSeries的chart,如何实现?

liujunsummer 2015-08-04 04:40:03

wpftoolkit里面好像没这样的控件,高手指导一下,感激不尽
...全文
327 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
倾醴欣雨 2021-06-28
  • 打赏
  • 举报
回复

虽然时间比较长了,我来回答一下吧,万一有人再碰到呢,重写DataPointStyle的模板具体代码:

  <Style x:Key="DataPointStyle" TargetType="Control">
                                                                    
                                                                    <Setter Property="Template">
                                                                        <Setter.Value>
                                                                            <ControlTemplate>
                                                                                <Grid>
                                                                                    <Grid>
                                                                                        <Grid.RowDefinitions>
                                                                                            <RowDefinition Height="{Binding FailCount}"/><!--需要多个就在这多写几个RowDefinition Height绑定比例就行-->
                                                                                            <RowDefinition/>
                                                                                        </Grid.RowDefinitions>
                                                                                        <Border Grid.Row="0" Background="Red"/>
                                                                                        <Border Grid.Row="1" Background="Lime"/>
                                                                                    </Grid>
                                                                                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Text="{Binding Num}" DockPanel.Dock="Top"/>
                                                                                </Grid>
                                                                            </ControlTemplate>
                                                                        </Setter.Value>
                                                                    </Setter>
                                                                </Style>

 <TK:ColumnSeries  DataContext="{Binding Counts}" Title="1" ItemsSource="{Binding States}"   DependentValuePath="Num" IndependentValuePath="Name"/>

 public class State:INotifyPropertyChanged
    {
        public State(string name)
        {
            this.Name = name;
        }
        string _Name;
        public string Name { get { return _Name; } set { _Name = value;  UpData(nameof(Name)); } }
        double _Num;
        public double Num { get { return _Num; }set { _Num = value; UpData(nameof(Num)); } }
        public string FailCount { get; set; }=“0*”//这个值需要在小数后加*代表比例,比如”0.8*“,代表占显示总长的80%
        public event PropertyChangedEventHandler PropertyChanged;
        public void UpData(string name)
        {
            PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(name));
        }
    }

States是State的集合,要显示几个的话多写几个FailCount一样的属性前台绑定就行,如果要显示不固定数量那就把grid换成ItemsControl结合Viewbox写就行,但后台FailCount就需要是集合了,当然我相信会这么写的也就会直接自己重新开发个控件了*_*,不过不会也没关系,可以私信我,大家都是从不会到会一步步过来的嘛《^_^》

liujunsummer 2015-08-05
  • 打赏
  • 举报
回复
请教各位大咖

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧