Need help for Drill Down from a chart with click on the bar?

Sep 5, 2009 at 6:50 AM

Hello I'm a newbie in WPF and I like to use the chart control from WPF Toolkit. The cahrt control is used like that:

<chartingToolkit:Chart
    Grid.Row="3"
    Background="{StaticResource backgroundColorLightBlue}"
    BorderBrush="Black" BorderThickness="0"
    Title="{Binding Source={StaticResource Lang}, XPath=chartGroupDepth/title/@Header}"
    Grid.Column="2"                                
    Margin="20,0,0,0"
    x:Name="dependencyChart">
    <chartingToolkit:ColumnSeries
        Title="{Binding Source={StaticResource Lang}, XPath=chartGroupDepth/titleColumn/@Header}"
        x:Name="chartGroupDepth"
        DependentValueBinding="{Binding DepthCount}" 
        IndependentValueBinding="{Binding DepthName}" 
    </chartingToolkit:ColumnSeries>
</chartingToolkit:Chart>

Now I like to a the click event on the bar (DataPoint?) to drill down. But if I'm using the MouseLeftButtonDown method the sender
is always the ColumnSeries and there is not the "graph" bar i clicked on. How can I implement the "OnClick" for the single bar 
element?
Each help I would appreciate much !!!
The result should be that I get back the "data" container I put in in the binding like it is with the 
method chartingToolkit:DataPointSeries.SelectionChanged="OnSelectionChanged">. But here the bar will be selected and still stay
selected. My goal is to open an datailed window (the original window still exist) and after closing I could not click anymore to 
the current "selected" bar. How could I delete the selection of that bar. In WinForms you just set a control.SelectedItem = -1, 
but in WPF?
I have an additonal request regarding the tooltip if I'm using the excellent code snippet my tooltip with the values disapears.
What do I need to do to get back the default behavior to see again my values?
        <chartingToolkit:ColumnSeries.DataPointStyle>
            <Style TargetType="chartingToolkit:ColumnDataPoint">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="chartingToolkit:ColumnDataPoint">
                            <Grid>
                                <Rectangle
                                    Fill="{TemplateBinding Background}"
                                    Stroke="Black"/>
                                <Grid
                                    Margin="0,-20"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Top">
                                    <TextBlock
                                        Text="{TemplateBinding FormattedDependentValue}"
                                        FontWeight="Bold"
                                        Margin="2"/>
                                </Grid>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </chartingToolkit:ColumnSeries.DataPointStyle>

Thanks for reading and I hope the questions are not so stupid. I'm lost and need urgently an idea ...
 
Sep 9, 2009 at 8:25 AM

I solved at least my Drill Down with the default setting I still investigate but from day to day it makes more fun to work with WPF.

Our solution we used now is:

<?xml version="1.0" encoding="utf-8"?>
<chartingToolkit:ColumnSeries
    Title="{Binding Source={StaticResource Lang}, XPath=chartGroupDepth/titleColumn/@Header}"
    x:Name="chartGroupDepth"
    DependentValueBinding="{Binding Count}"
    IndependentValueBinding="{Binding Name}"
    IsSelectionEnabled="True"
    chartingToolkit:DataPointSeries.SelectionChanged="ChartOnSelectionChanged"
    MouseEnter="EnterInAColumnSeries"
    MouseLeave="LeaveAColumnSeries">
</chartingToolkit:ColumnSeries>

 

The code behinde is:

private void GroupDepthChartOnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.AddedItems.Count >= 1)
    {
        if (null != this.chart.SelectedItem)
        {                   
            // Do something with the SelectedItemObject ...
            this.chartGroupDepth.SelectedItem = null;
        }
    }            
}

private void EnterInAColumnSeries(object sender, MouseEventArgs e)
{
    this.Cursor = Cursors.Hand;
}

private void LeaveAColumnSeries(object sender, MouseEventArgs e)
{
    this.Cursor = null;            
}

We found it easier if the mouse go over the bar that a cursor cahnge indecate that you can click on it for drill down ...
Have a nice day
Mike aka Shrek1910