Hi everyone,
I have a Chart with FreeformPointLineSeries.
My representation of data is like this:
Serie1: ColorCode1, XYCoordinates1
Serie2: ColorCode2, XYCoordinates2
Serie3: ColorCode3, XYCoordinates3
Serie4: ColorCode4, XYCoordinates4
Serie5: ColorCode1, XYCoordinates5
Serie6: ColorCode2, XYCoordinates6
Serie7: ColorCode3, XYCoordinates7
Serie8: ColorCode4, XYCoordinates8
My question is: is there any way I can group by ColorCode when displaying the legend?
I want all series to be displayed as individual Curves on the Chart, but I want the possibility to group by a criteria in the legend and also keep the link between the Legend items and Chart curves.
For the example above, the behavior I'm looking for is a Legend with 4 items (ColorCode1-4). When I Select only ColorCode1, on the Chart I can see Serie1 and Serie5.
Any ideas on how I could achieve this?
Regards,
giryhepai
Legend with grouped series
Moderator: Queue Moderators
-
- Posts: 141
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Legend with grouped series
Hello,
I think the easiest way to do this is to have an extra FreeformPointLineSeries with no points for each color code. Then you check inside CheckBoxStateChanged -event which color code series is turned on/off, and turn the visibility of the respective series true/false. Set ShowInLegendBox to false for the series which actually have some datapoints, in this case Serie1, Serie2 etc.
To create blank series:
Subscribing to the CheckBoxStateChanged -event, and what it contains:
Alternatively, you can check the series title inside the event and manually turn off the respective series. For example:
Hope this is helpful.
I think the easiest way to do this is to have an extra FreeformPointLineSeries with no points for each color code. Then you check inside CheckBoxStateChanged -event which color code series is turned on/off, and turn the visibility of the respective series true/false. Set ShowInLegendBox to false for the series which actually have some datapoints, in this case Serie1, Serie2 etc.
Code: Select all
Serie1.ShowInLegendBox = false;
Code: Select all
FreeformPointLineSeries greens = new FreeformPointLineSeries(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
greens.Title.Text = "Greens";
greens.LineStyle.Color = Colors.Green;
_chart.ViewXY.FreeformPointLineSeries.Add(greens);
Code: Select all
_chart.ViewXY.LegendBoxes[0].CheckBoxStateChanged += Legend_CheckBoxStateChanged;
private void Legend_CheckBoxStateChanged(object sender, Arction.Wpf.Charting.Views.CheckBoxStateChangedEventArgs e)
{
_chart.BeginUpdate();
var series = e.Series as FreeformPointLineSeries;
Color color = series.LineStyle.Color;
foreach (FreeformPointLineSeries fpls in _chart.ViewXY.FreeformPointLineSeries)
{
if (fpls.LineStyle.Color == color) // Turn off all series having the same color
fpls.Visible = e.IsChecked;
}
_chart.EndUpdate();
}
Code: Select all
if (series.Title.Text == "Greens")
{
_chart.ViewXY.FreeformPointLineSeries[0].Visible = e.IsChecked;
_chart.ViewXY.FreeformPointLineSeries[4].Visible = e.IsChecked;
}
Re: Legend with grouped series
Hi LasseP,
This was exactly what I was looking for.
Worked like a charm!
Thanks a bunch,
giryhepai
This was exactly what I was looking for.
Worked like a charm!
Thanks a bunch,
giryhepai