Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

c# - WPF Toolkit BarSeries descending order

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?

question from:https://stackoverflow.com/questions/65872006/wpf-toolkit-barseries-descending-order

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...