Hi,
Is there a way to define the position (Top/bottom/right/left) of the legend box rather than dragging it?
Legend position setting
Moderator: Arction_LasseP
-
- Posts: 137
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Legend position setting
Hello,
Yes there is. You can define the position of the Legend Box by setting its Position property to one of the pre-defined locations such as TopLeft, BottomRight or RightCenter, or to Manual, in which case you can use Offset to set its exact position. Offset is the screen coordinates relative to chart's top-left corner.
Best regards,
Lasse
Yes there is. You can define the position of the Legend Box by setting its Position property to one of the pre-defined locations such as TopLeft, BottomRight or RightCenter, or to Manual, in which case you can use Offset to set its exact position. Offset is the screen coordinates relative to chart's top-left corner.
Code: Select all
_chart.ViewXY.LegendBoxes[0].Position = LegendBoxPositionXY.Manual;
_chart.ViewXY.LegendBoxes[0].Offset.SetValues(100, 100);
Lasse
-
- Posts: 4
- Joined: Mon Jun 20, 2022 3:23 pm
Re: Legend position setting
thanks for your answer, sorry I think I didn't ask properly about my intention.
Is there anyway to have a docking function of the legend box and share it between different charts?
Is there anyway to have a docking function of the legend box and share it between different charts?
-
- Posts: 137
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Legend position setting
Besides the automatic positioning options (BottomRight, RightCenter etc.) there isn't that kind of docking option ready. However, it is most likely possible to built that yourself using existing methods and properties. How this is done depends on where exactly you want to position the Legend. Try modifying Position and Offset properties to see if you can get the desired location. If you need to update the Legend's position when for example adding or resizing charts, you need to adjust those properties in some event such as chart.SizeChanged or chart.Loaded.
It should be noted that a Legend Box is tied to the chart it belongs to. Therefore in case of multiple charts, the Legend Box can only be on top of its chart, not over other charts. Also it can only display series that belong to that chart. If you want to have one legend box for multiple chart, it is possible to create empty series (series with no data points) as placeholders for the series in other charts.
Kind regards,
Lasse
It should be noted that a Legend Box is tied to the chart it belongs to. Therefore in case of multiple charts, the Legend Box can only be on top of its chart, not over other charts. Also it can only display series that belong to that chart. If you want to have one legend box for multiple chart, it is possible to create empty series (series with no data points) as placeholders for the series in other charts.
Kind regards,
Lasse
-
- Posts: 4
- Joined: Mon Jun 20, 2022 3:23 pm
Re: Legend position setting
Hi,
Thank you for your answer.
However, I don't quite understand "create an empty series as a placeholder for other series".
Do I put the legend in that empty series and somehow access data from other charts?
Thank you for your answer.
However, I don't quite understand "create an empty series as a placeholder for other series".
Do I put the legend in that empty series and somehow access data from other charts?
-
- Posts: 137
- Joined: Wed Mar 27, 2019 1:05 pm
Re: Legend position setting
Hi,
What I mean by empty series as placeholder is that if you want to show series that are not in the chart the Legend Box belongs to, you can create an empty series with the same Title as the series in other chart. The Legend Box automatically shows all series in the chart unless ShowInLegendBox property is disabled for the series. This allows you to have one Legend Box for multiple charts.
How this works in practice is:
-Whenever you create a series in some other chart, also create a series in the main chart (the one with the Legend)
-Give this series the same Title, and possibly LineColor, but no data points.
-Don't show the Legend Boxes in other charts.
-To apply interaction between the Legend Box empty series and the actual series in other charts, use events such as CheckBoxStateChanged, HighlightedStateChanged, or one of the SeriesTitleMouse events. Note that the SeriesTitleMouse-events do not work unless MoveFromSeriesTitle for the Legend Box is disabled.
A simple example code:
Best regards,
Lasse
What I mean by empty series as placeholder is that if you want to show series that are not in the chart the Legend Box belongs to, you can create an empty series with the same Title as the series in other chart. The Legend Box automatically shows all series in the chart unless ShowInLegendBox property is disabled for the series. This allows you to have one Legend Box for multiple charts.
How this works in practice is:
-Whenever you create a series in some other chart, also create a series in the main chart (the one with the Legend)
-Give this series the same Title, and possibly LineColor, but no data points.
-Don't show the Legend Boxes in other charts.
-To apply interaction between the Legend Box empty series and the actual series in other charts, use events such as CheckBoxStateChanged, HighlightedStateChanged, or one of the SeriesTitleMouse events. Note that the SeriesTitleMouse-events do not work unless MoveFromSeriesTitle for the Legend Box is disabled.
A simple example code:
Code: Select all
_chart.ViewXY.LegendBoxes[0].CheckBoxStateChanged += LegendBox_CheckBoxStateChanged;
private void LegendBox_CheckBoxStateChanged(object sender, Arction.Wpf.Charting.Views.CheckBoxStateChangedEventArgs e)
{
if (e.Series == emptySeries)
{
seriesInOtherChart.Visible = e.IsChecked;
}
}
Lasse