knockando
knockando

Reputation: 1012

Retrieve Value on Mouse Click for WPF Column Series

I have a simple chart with two column series containing all months in the year. I want to filter a list view that show detailed information for the selected month. I can capture the event via MouseDown on the ColumnSeries but I'm not sure how to get to the month in the column series.

<DVC:ColumnSeries Title=" Expenditures" IndependentValueBinding="{Binding Path=Month}"
                  DependentValueBinding="{Binding Path=Amt}"
                  ItemsSource="{Binding Path=ActivityExpenditureSeries}"
                  MouseDown="ColumnSeries_MouseDown" />

I'm sure I could do some fancy WPF databinding to the selected ColumnSeries for the listviews ItemsSource but this is where I'm heading:

Private Sub ColumnSeries_MouseDown(ByVal sender As System.Object,
                                   ByVal e As System.Windows.Input.MouseButtonEventArgs)
    ' This is the functionality I'm looking for...
    Dim selectedColumn As String
    FilterListView(selectedColumn)
End Sub

Upvotes: 0

Views: 2741

Answers (4)

JAnton
JAnton

Reputation: 1115

[In C#] Previous answers only allow clicking when selections are changed. Following code will enable clicking on columns independently of where you clicked earlier. It will also allow right clicking if needed (change event type)

<chartingToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True">
 <chartingToolkit:ColumnSeries.DataPointStyle>
  <Style TargetType="chartingToolkit:ColumnDataPoint">
       <EventSetter Event="MouseLeftButtonUp" Handler="ColumnSeries_ColumnLeftClicked"/>
  </Style>
 </chartingToolkit:ColumnSeries.DataPointStyle>
</chartingToolkit:ColumnSeries>

private void ColumnSeries_ColumnLeftClicked(object sender, MouseButtonEventArgs e)
{
    var key = ((ColumnDataPoint)sender).IndependentValue;
    //etc
}

Upvotes: 0

Strong84
Strong84

Reputation: 1979

Example in C#:

Set the IsSelectionEnabled=True on the series and added a SelectionChanged event to the same series.

Name Space:

using System.Windows.Controls.DataVisualization.Charting;

Method:

private void ColumnSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                ColumnSeries cs = (ColumnSeries)sender;
                KeyValuePair<string, int> kv = (KeyValuePair<string, int>)cs.SelectedItem;

                Debug.WriteLine(kv.Key);
                Debug.WriteLine(kv.Value);
            }

Upvotes: 0

knockando
knockando

Reputation: 1012

Set the IsSelectionEnabled=True on the series and added a SelectionChanged event to the same series.

Private Sub colSeries_adjExpenditure_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
        Dim cs As ColumnSeries = CType(sender, ColumnSeries)
        Dim dp As MyDataPoint = CType(cs.SelectedItem, MyDataPoint)
End Sub

Upvotes: 4

Sandipan Sengupta
Sandipan Sengupta

Reputation: 9

Set the IsSelectionEnabled=True on the series and added a SelectionChanged event to the same series.

System.Windows.Controls.DataVisualization.Charting.ColumnSeries cs = (System.Windows.Controls.DataVisualization.Charting.ColumnSeries)sender;
System.Data.DataRowView dp = (System.Data.DataRowView)cs.SelectedItem;
tbkName.Text = dp.Row[1].ToString();
tbkSalary.Text = dp.Row[0].ToString();

Upvotes: 0

Related Questions