WPF Toolkit BarSeries descending order

135 Views Asked by At

Is it possible to set the sorting of WPF toolkit System.Windows.Controls.DataVisualization.Charting.BarSeries? I have following bar chart:

<dvc:Chart x:Name="BarChart">
        <dvc:Chart.Axes>
            <dvc:CategoryAxis Orientation="X">
                <dvc:CategoryAxis.Style>
                    <Style TargetType="{x:Type dvc:CategoryAxis}" >
                        <Setter Property="LayoutTransform">
                            <Setter.Value>
                                <RotateTransform  Angle="-180" />
                            </Setter.Value>
                        </Setter>
                    </Style>
                </dvc:CategoryAxis.Style>
                <dvc:CategoryAxis.AxisLabelStyle>
                    <Style x:Name="labelStyleX1" TargetType="Control">
                        <Setter Property="FontSize" Value="15"/>
                        <Setter Property="LayoutTransform" >
                            <Setter.Value>
                                <RotateTransform  Angle="-45" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Foreground" Value="Black"/>
                    </Style>
                </dvc:CategoryAxis.AxisLabelStyle>
            </dvc:CategoryAxis>
        </dvc:Chart.Axes>
        <dvc:Chart.Series>
            <dvc:BarSeries ItemsSource="{Binding Overall}"
                           DependentValueBinding="{Binding Path=Value}"
                           IndependentValuePath="Key"
                           Title="Overall"
                           x:Name="overBar">
                <dvc:BarSeries.Style>
                    <Style TargetType="{x:Type dvc:BarSeries}" >
                        <Setter Property="LayoutTransform">
                            <Setter.Value>
                                <RotateTransform  Angle="-180" />
                            </Setter.Value>
                        </Setter>
                    </Style>
                </dvc:BarSeries.Style>
        </dvc:BarSeries>
</dvc:Chart.Series>
    </dvc:Chart>

Since CategoryAxis.SortOrder doesn't affect anything, I tried to manually rotate it by 180 degrees, but axis doesn't rotate, leaving labels on the wrong places. The binded dictinary is definitely sorted, but this sorting is ignored by control:

Antecedent = new Dictionary<string, int>(Antecedent.OrderByDescending(x => x.Value).Take(MaxStats));

I also tried this solution, but it doesn't help. Though values are negated, sort order doesn't change: enter image description here

How can I flip this series upside down, to have the most values at the top of the plot?

1

There are 1 best solutions below

0
user2250152 On

You should sort values in ascending order not descending order.

Try to use OrderBy instead of OrderByDescending

Antecedent = new Dictionary<string, int>(Antecedent.OrderBy(x => x.Value).Take(MaxStats));

If it won't work then please share a code what you are assigning to Overall property because you are binding ItemsSource to Overall property.