0 Replies - 7089 Views - Last Post: 17 July 2013 - 07:09 PM Rate Topic: -----

#1 solarissf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 27-March 12

wpfchart sort y axis, but by x axis values

Posted 17 July 2013 - 07:09 PM

Hello everyone

I'm working on a project in VS2012 wpf.
From an xml file I create an observable collection. Then once I have an observable collection, I bind a datagrid and bar chart to that collection. All this works accurately as you can see in the screen shot. Here is the question...

The bar chart.. the x axis are percentages... the y axis is just the name. I made a custom datapoint label that shows the y and x axis together. Now... how can I sort the y axis.. but the catch is I don't want to sort by the y axis names... I want to sort by the percentage number (the x axis).

So to be confusing... I would like to sort the y axis, by x axis values... highest percentages on top.

Can someone please point me in the correct direction.

Thanks so much!

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:xxxxxatch_v1"
        x:Class="Clxxxxtch_v1.MainWindow"
        xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
        xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
        Title="MainWindow" Height="651" Width="800">
        <!--xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"-->


    <window.Resources>
        <local:DataBindingClass x:Key="formatter"/>
        <Style x:Key="tester">
            
        </Style>
    </window.Resources>



   

        <Grid Background="#FFE4E4E4">
            <Grid HorizontalAlignment="Left" Height="486" VerticalAlignment="Top" Width="772" Margin="10,80,0,0">
            <Grid.Background>
                <ImageBrush/>
            </Grid.Background>

            <DataGrid x:Name="DataGridPerformance" 
            	AutoGenerateColumns="False"
            	HorizontalAlignment="Right" 
            	VerticalAlignment="Top" 
            	MaxHeight="250" 
            	Width="423"
            	Margin="0,10,10,0"
            	ColumnWidth="*"
            	Background="Black"
                CanUserAddRows="False">

                <DataGrid.Columns>
                    <DataGridTextColumn Header="Acct Num" Binding="{Binding tName}"/>
                    <DataGridTextColumn Header="Acct Desc" Binding="{Binding tDesc}"/>

                    <DataGridTextColumn Header="Net P/L" Binding="{Binding tPL, ConverterParameter=PL, Converter={StaticResource formatter}}">
                        <DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Foreground" Value="{Binding tPL, ConverterParameter=COLOR, Converter={StaticResource formatter}}"/>
                            </Style>
                        </DataGridTextColumn.ElementStyle>
                    </DataGridTextColumn>

                    <DataGridTextColumn Header="Pct G/L" Binding="{Binding tPerc, ConverterParameter=PERC, Converter={StaticResource formatter}}">
                        <DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Foreground" Value="{Binding tPerc, ConverterParameter=COLOR, Converter={StaticResource formatter}}"/>
                            </Style>
                        </DataGridTextColumn.ElementStyle>
                    </DataGridTextColumn>

                </DataGrid.Columns>

                <DataGrid.AlternatingRowBackground>
                    <LinearGradientBrush EndPoint="0.5,0.0" StartPoint="0.5,1.0">
                        <GradientStop Color="#FFFEFEFF" Offset="0"/>
                        <GradientStop Color="#FFE4F0FC" Offset="1"/>
                    </LinearGradientBrush>
                </DataGrid.AlternatingRowBackground>
                <DataGrid.Effect>
                    <DropShadowEffect ShadowDepth="10"/>
                </DataGrid.Effect>

            </DataGrid>
            <ListBox x:Name="logger" HorizontalAlignment="Left" Height="100" Margin="524,376,0,0" VerticalAlignment="Top" Width="238" Foreground="White" Background="#FF191919"/>
            <TextBox x:Name="TextBoxAddress" HorizontalAlignment="Right" Height="20" Margin="0,483,-58,-89" TextWrapping="Wrap" Text="internalftp-test.jefferies.com" VerticalAlignment="Top" Width="151" Visibility="Visible"/>




            <chartingToolkit:Chart
                Name="ManagerBarPerc" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Stretch"
                Margin="10,10,0,10" 
                Width="250"
                MinHeight="466"
                xml:lang="en-US"
                >
                <chartingToolkit:Chart.Effect>
                    <DropShadowEffect/>
                </chartingToolkit:Chart.Effect>
                
                <chartingToolkit:Chart.Background>
                    <LinearGradientBrush>
                        <GradientStop Color="AliceBlue" Offset="0"/>
                        <GradientStop Color="white" Offset="1"/>
                    </LinearGradientBrush>
                </chartingToolkit:Chart.Background>

                <!--Start Format x axis-->
                <chartingToolkit:Chart.Axes>
                    <chartingToolkit:LinearAxis
                        Orientation="X" ShowGridLines="True" >
                        <chartingToolkit:LinearAxis.AxisLabelStyle>
                            <Style TargetType="chartingToolkit:AxisLabel">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="chartingToolkit:AxisLabel">
                                            <TextBlock Text="{Binding ConverterParameter=AXIS, Converter={StaticResource formatter}}"/>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </chartingToolkit:LinearAxis.AxisLabelStyle>
                    </chartingToolkit:LinearAxis>

                    <!--<chartingToolkit:LinearAxis
                        Orientation="Y" Location="Left" Visibility="Hidden" Width="0">
                    </chartingToolkit:LinearAxis>-->
                </chartingToolkit:Chart.Axes>
                <!--End Format x axis-->


                <chartingToolkit:Chart.LegendStyle>
                    <Style TargetType="Control">
                        <Setter Property="Width" Value="0"/>
                        <Setter Property="Height" Value="0"/>
                    </Style>
                </chartingToolkit:Chart.LegendStyle>
                
                <chartingToolkit:BarSeries 
                    DependentValuePath="tPerc"
                    IndependentValuePath="tDesc"
                    ItemsSource="{Binding}"
                    >

                    <chartingToolkit:BarSeries.IndependentAxis>
                        <chartingToolkit:CategoryAxis Orientation="Y" Visibility="Hidden" Width="0" />
                    </chartingToolkit:BarSeries.IndependentAxis>
                    
                    <chartingToolkit:BarSeries.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </chartingToolkit:BarSeries.Background>


                    <chartingToolkit:BarSeries.DataPointStyle>
                        <Style TargetType="chartingToolkit:BarDataPoint">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="chartingToolkit:BarDataPoint">
                                        <Grid>
                                            <Border
                                                BorderBrush="Black"
                                                BorderThickness="1">
                                                    <Rectangle>
                                                        <Rectangle.Fill>
                                                            <LinearGradientBrush>
                                                                <GradientStop Color="#FF4A6BDC" Offset="0"/>
                                                                <GradientStop Color="#FF6A6B6C" Offset="1"/>
                                                            </LinearGradientBrush>
                                                        </Rectangle.Fill>
                                                    </Rectangle>
                                            </Border>
                                            <Grid
                                                Margin="-60"
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center">
                                                <StackPanel Margin="0" Orientation="Horizontal">
                                                    <TextBlock
                                                        Text="{TemplateBinding FormattedIndependentValue}"
                                                        FontWeight="Bold"
                                                        Margin="0">
                                                    </TextBlock>
                                                    <TextBlock
                                                        Text=" "
                                                        FontWeight="Bold">
                                                    </TextBlock>
                                                    <TextBlock
                                                        Text="{TemplateBinding FormattedDependentValue, ConverterParameter=PERC, Converter={StaticResource formatter}}"
                                                        FontWeight="Bold"
                                                        Margin="0">
                                                    </TextBlock>
                                                </StackPanel>
                                            </Grid>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </chartingToolkit:BarSeries.DataPointStyle>



                    <!--<chartingToolkit:BarSeries.DataPointStyle>
                        <Style TargetType="chartingToolkit:BarDataPoint">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="chartingToolkit:BarDataPoint">
                                        <Grid>
                                            <Border
                                                BorderBrush="Black"
                                                BorderThickness="1">
                                                <Rectangle>
                                                    <Rectangle.Fill>
                                                        <LinearGradientBrush>
                                                            <GradientStop Color="#FF4A6BDC" Offset="0"/>
                                                            <GradientStop Color="#FF6A6B6C" Offset="1"/>
                                                        </LinearGradientBrush>
                                                    </Rectangle.Fill>
                                                </Rectangle>
                                            </Border>

                                            <TextBlock
                                                            Text="{TemplateBinding Property=FormattedIndependentValue}"
                                                            FontWeight="Bold"
                                                            Foreground="Black"
                                                            Margin="0"/>

                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                       </Style>
                    </chartingToolkit:BarSeries.DataPointStyle>-->
                </chartingToolkit:BarSeries>

            </chartingToolkit:Chart>

            <!--THIS IS A TEST AREA !!!!!!!!!!!!!!!!!!!!!!-->
            
            

            
            
            
            
            <ListView x:Name="lstNames" HorizontalAlignment="Left" Height="100" Margin="349,376,0,0" VerticalAlignment="Top" Width="161">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding tName}"/>
                        <GridViewColumn Header="Percentage" DisplayMemberBinding="{Binding tPerc}"/>
                    </GridView>
                </ListView.View>
            </ListView>
            
            





        </Grid>

        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top" MinHeight="75">


            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FF4C536A" Offset="1"/>
                </LinearGradientBrush>
            </Grid.Background>
            <Label Content="Pxxxxx.1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="193" Background="{x:Null}" Foreground="#FFFFFBFB" Margin="10,5,0,0" FontSize="20"/>

            <StackPanel Orientation="Horizontal" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Stretch">

                <Button Content="Create XML"  Margin="10,0,0,5" VerticalAlignment="Bottom" Width="100" Click="Button_Click" Foreground="White">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="#FF4C536A" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>



                <Button Content="Load XML" Margin="10,0,0,5" VerticalAlignment="Bottom" Width="100" Click="Button_Click_1" Foreground="White" >
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="#FF4C536A" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>

                <Button Content="Pop TopRight" Margin="10,0,0,5" VerticalAlignment="Bottom" Width="100" Click="Button_Click_2" Foreground="White" >
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="#FF4C536A" Offset="1"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>

            </StackPanel>

            <StackPanel Orientation="Horizontal" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Right">
                <Label Content="User Name" Height="25" Margin="0,0,10,0"  Foreground="White"/>
                <TextBox x:Name="TextBoxUsername"  Height="20" Margin="0,0,10,0" TextWrapping="Wrap" Text="xxxx01" Width="100"/>
                <Label Content="Password" Height="25" Margin="0,0,10,0" Foreground="White" />
                <TextBox x:Name="TextBoxPW" Height="20" Margin="0,0,10,0" TextWrapping="Wrap" Text="xxxai"  Width="100"/>
            </StackPanel>
            <Button x:Name="ButtonTester" Content="Pop TopRight" Margin="360,0,332,-372" VerticalAlignment="Bottom" Click="ButtonTester_Click" Foreground="White" >
                <Button.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="Black" Offset="0"/>
                        <GradientStop Color="#FF4C536A" Offset="1"/>
                    </LinearGradientBrush>
                </Button.Background>
            </Button>


        </Grid>

        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Bottom" MinHeight="50">
            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FF4C536A" Offset="1"/>
                </LinearGradientBrush>
            </Grid.Background>
            <StackPanel Orientation="Horizontal" Height="30" HorizontalAlignment="Left">
                <Label Content="Update Time:" Height="30" Margin="10,0,0,0" MinWidth="60" Foreground="White" FontSize="12"/>
                <TextBox x:Name="txtboxUpdateTime" Height="20" Margin="10,0,0,0" MinWidth="200" Text="{Binding Timer}" Foreground="Blue">
                    <TextBox.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </TextBox.Background>
                </TextBox>
                <Label Content="Filename:" Height="30" Margin="10,0,0,0" MinWidth="60" Foreground="White" FontSize="12"/>
                <TextBox x:Name="txtboxUpdateFilename" Height="20" Margin="10,0,0,0" MinWidth="200" Text="{Binding Name}" Foreground="DarkBlue">
                    <TextBox.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </TextBox.Background>
                </TextBox>
            </StackPanel>
        </Grid>
    </Grid>


</Window>

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1