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" Independ开发者_Python百科entValueBinding="{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
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
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();
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);
}
[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
}
精彩评论