
+2
Individual column/bar selection.
I've been trying to figure this out all night and haven't managed to find any code or any discussions to assist me with this one. Similar discussions were focused on points in scatter and line charts, but nothing regarding columns or bars.
I have a requirement of being able to select individual columns in a column chart to access related data; however, none of my attempts at handling selection changed or mouse down produced any viable results. SelectionChanged event doesn't even fire for me and no visible selection happens. SelectionColor for the model does not appear to do anything and SelectionMode doesn't produce any visible behavior with selection enabled in the ColumnSeries.
I have a requirement of being able to select individual columns in a column chart to access related data; however, none of my attempts at handling selection changed or mouse down produced any viable results. SelectionChanged event doesn't even fire for me and no visible selection happens. SelectionColor for the model does not appear to do anything and SelectionMode doesn't produce any visible behavior with selection enabled in the ColumnSeries.
Customer support service by UserEcho
So, that works great for getting the data, which was my major requirement. However, I can't seem figure out how to interact with the actual column, to change its color, so that there is a feedback for the user regarding their selection. My column series looks like this:
Since selectable or selection mode does nothing (it appears), I need to find a work-around for getting the column itself and changing its color.
I would think that I'd be able to get at it using the Items property, but it doesn't show any items. I'm able to get the source item based on the nearest point, but not its ColumnItem. ActualItems is protected, so I can't get columns out of that:
Adding the Label allows me to bind it to the CategoryAxis. Likewise, ID is used for internal data identification and linking. So, then, I simply wrapped my data into this new object and passed it to the ColumnSeries' Items property by using the AddRange() method.
I changed the previous code that got the item and its data to look at Items and the ColumnItem instead:
Obviously, the color changing during selection has not been developed much, since I'm out of time today, but it's very easy to track selection, so this is a good basis for anyone else who ran into the same issue as I. Basically, all you have to do is track a SelectedItem, which is null by default, but then simply point to whatever item you click on. When a new click happens, you change the existing SelectedItem, if it's not null, to the default state, and make the new item as the selected one. And to get the underlying data, beyond the value, I would cast to Item instead of ColumnItem.
For reusability, since this scenario comes around very often in my projects, I'll probably derive a new class from ColumnSeries that does all of that by default.
I tried making it more generic, using BarSeriesBase and BarItemBase, but that requires a bit more work and I am dead tired.
Note that I'm using MVVM Light framework, so that's where ViewModelBase comes from.
Here's the code again, just in case pastebin link is broken.