Page 1 of 1
When you click the legend, series high light?
Posted: Thu Sep 05, 2024 2:18 am
by 16092152
How do I implement the series high light function when I click the Legend item.
My environment is .net8 and wpf.
I always appreciate your help.
Re: When you click the legend, series high light?
Posted: Thu Sep 05, 2024 4:47 am
by 16092152
The latest version of Nuget is fine, but the source code version I have is getting an error.
No overload for 'Chart2_ClickLegend' matching 'MouseEventHandler' delegate.(CS0123)
// The following error occurs.
Chart2.ClickLegend += Chart2_ClickLegend;
private void Chart2_ClickLegend(object sender, Steema.TeeChart.Drawing.MouseEventArgs e)
{
int index = Chart2.Legend.Clicked(e.X, e.Y);
if (index > -1)
{
for (int i = 0; i < Chart2.Series.Count; i++)
{
Chart2.Transparency = 0;
if (i != index)
{
Chart2.Transparency = 70;
}
}
}
}
Re: When you click the legend, series high light?
Posted: Thu Sep 05, 2024 7:31 am
by edu
Hello,
private void Chart2_ClickLegend(object sender, Steema.TeeChart.Drawing.MouseEventArgs e)
This should be
private void _chart1_ClickLegend(object sender, System.Windows.Input.MouseEventArgs e)
instead.
In WPF, to get X and Y values you can't access e.X and e.Y the same way as in Winforms. Here's a way to do so:
Code: Select all
private void _chart1_ClickLegend(object sender, System.Windows.Input.MouseEventArgs e)
{
Point clickedPoint = e.GetPosition(_chart1);
double x = clickedPoint.X;
double y = clickedPoint.Y;
int index = _chart1.Legend.Clicked((int)x,(int)y);
// Replicating your code. Add changes if necessary
if (index > -1)
{
for (int i = 0; i<_chart1.Series.Count; i++)
{
_chart1.Series[i].Transparency = 0;
if (i != index) _chart1.Series[i].Transparency = 70;
}
}
}
ClickLegend is a nice way to implement your custom highlight strategy, however, if you only want to click legend items to hide them, for example, you can use
Legend.ActiveStyle instead. Note, however, that LegendActiveStyles.Checkbox, which is one of the different styles available, is not compatible with WPF. You can use
_chart1.Legend.ActiveStyle = LegendActiveStyles.Opacity;
or
_chart1.Legend.ActiveStyle = LegendActiveStyles.LineThrough;
If there's anything else I can help you with, please let me know.
Best regards,
Edu
Re: When you click the legend, series high light?
Posted: Thu Sep 05, 2024 8:33 am
by 16092152
For the source you sent, the same legend clicked disappears.
The source version does not appear to be the same as the nuget version.
The nuget version works fine, but only the source version disappears from the legend's series and works strangely.
private void Chart2_ClickLegend(object sender, System.Windows.Input.MouseEventArgs e)
{
System.Windows.Point clickedPoint = e.GetPosition(Chart2);
double x = clickedPoint.X;
double y = clickedPoint.Y;
int index = Chart2.Legend.Clicked((int)x, (int)y);
// Replicating your code. Add changes if necessary
if (index > -1)
{
for (int i = 0; i < Chart2.Series.Count; i++)
{
Chart2.Series.Transparency = 0;
if (i != index) Chart2.Series.Transparency = 70;
}
}
// Error CS1061 'Legend' does not include a definition for 'ActiveStyle'.
Chart1.Legend.ActiveStyle = LegendActiveStyles.Opacity; 'ActiveStyle'. // Error
Chart1.Legend.ActiveStyle = LegendActiveStyles.LineThrough; // Error CS1061
}
Re: When you click the legend, series high light?
Posted: Thu Sep 05, 2024 8:36 am
by 16092152
If you double-click on the items in the Legend box, all of those Legend items and chart series also disappear.
Re: When you click the legend, series high light?
Posted: Thu Sep 05, 2024 11:43 am
by edu
Hello,
// Error CS1061 'Legend' does not include a definition for 'ActiveStyle'.
Chart1.Legend.ActiveStyle = LegendActiveStyles.Opacity; 'ActiveStyle'. // Error
Chart1.Legend.ActiveStyle = LegendActiveStyles.LineThrough; // Error CS1061
Please note that activeStyle is a recent new feature so if you are testing with the source code version, be sure to be using the latest version.
With the code you provided (and a few tweaks to make it work with WPF), this is the result I'm getting:
https://www.steema.com/files/public/dem ... Click1.gif
And this is the result you'd get using LegendActiveStyles (LineThrough, in this example)
https://www.steema.com/files/public/dem ... Click2.gif
If you double-click on the items in the Legend box, all of those Legend items and chart series also disappear.
The expected behavior when using LegendActiveStyles is to be able to quickly select which series are to be active or not through legend clicks. If you combine LegendActiveStyles with custom code inside ClickLegend event, weird interactions may occur. I'd suggest using them separately but they can definitely co-exist.
If there's anything else I can help you with, let me know!
Best regards,
Edu