关于WPF使用Dev插件绘制柱状图着色问题 - Ultron Blog
2018/08/18 23:26

关于WPF使用Dev插件绘制柱状图着色问题

问题

输入图片说明

要求柱状图中柱子以不同的颜色展示,经过查资料,发现用下面很简单的方法就能实现

解决方法

方法很简单,只需要使用ColorEach属性,在xaml文件中对应柱状图定义的地方将ColorEach设置为True即可,具体代码如下

<dxc:ChartControl Name="chartControl1"  DataSource="{Binding QuestionChartDataInfos_Chart}"  >
    <dxc:ChartControl.Titles>
        <dxc:Title Content="{Binding ChartTitleMain}" HorizontalAlignment="Center" />
    </dxc:ChartControl.Titles>
    <dxc:XYDiagram2D  >
        <dxc:XYDiagram2D.DefaultPane>
            <dxc:Pane MirrorHeight="45" />
        </dxc:XYDiagram2D.DefaultPane>
        <dxc:XYDiagram2D.SecondaryAxesY>
            <dxc:SecondaryAxisY2D x:Name="y21">
            </dxc:SecondaryAxisY2D>
        </dxc:XYDiagram2D.SecondaryAxesY>
        <dxc:XYDiagram2D.AxisY>
            <dxc:AxisY2D x:Name="Hlb_firstY1" GridLinesMinorVisible="True">
            </dxc:AxisY2D>
        </dxc:XYDiagram2D.AxisY>
        <dxc:XYDiagram2D.AxisX>
            <dxc:AxisX2D GridLinesMinorVisible="True">
                <dxc:AxisX2D.Label>
                    <dxc:AxisLabel Padding="0">
                        <dxc:AxisLabel.ElementTemplate>
                            <DataTemplate >
                                <ContentPresenter Content="{Binding Path=Content}">
                                </ContentPresenter>
                            </DataTemplate>
                        </dxc:AxisLabel.ElementTemplate>
                    </dxc:AxisLabel>
                </dxc:AxisX2D.Label>
            </dxc:AxisX2D>
        </dxc:XYDiagram2D.AxisX>
        <!--在此处添加ColorEach属性即可-->
        <dxc:BarSideBySideSeries2D ColorEach="True" AnimationAutoStartMode="PlayOnce" LabelsVisibility="True"  dxc:XYDiagram2D.SeriesAxisY="{Binding ElementName=y21}"
                ArgumentDataMember="KFYYNR" ValueDataMember="WTGS" 
                CrosshairLabelPattern="{}问题个数: {V}" BarWidth="1">
            <dxc:BarSideBySideSeries2D.Label>
                <dxc:SeriesLabel ResolveOverlappingMode="Default" TextPattern="{}{V}个" />
            </dxc:BarSideBySideSeries2D.Label>
        </dxc:BarSideBySideSeries2D>
        <!--在此处添加ColorEach属性即可-->
        <dxc:LineSeries2D ColorEach="True" AnimationAutoStartMode="PlayOnce" LabelsVisibility="True"  dxc:XYDiagram2D.SeriesAxisY="{Binding ElementName=Hlb_firstY1}"
                ArgumentDataMember="KFYYNR" ValueDataMember="KFBFB_ZXT" CrosshairLabelPattern="{}百分比: {V}%">
            <dxc:LineSeries2D.Label>
                <dxc:SeriesLabel ResolveOverlappingMode="Default" Indent="25" dxc:MarkerSeries2D.Angle="-120" TextPattern="{}{V}%" />
            </dxc:LineSeries2D.Label>
        </dxc:LineSeries2D>
    </dxc:XYDiagram2D>
</dxc:ChartControl>

效果

输入图片说明


Tags:
WPF DevExpress
Stats:
4 条评论
338 次点击   4 次点赞