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.
When you click the legend, series high light?
-
- Newbie
- Posts: 9
- Joined: Fri Oct 22, 2021 12:00 am
-
- Newbie
- Posts: 9
- Joined: Fri Oct 22, 2021 12:00 am
Re: When you click the legend, series high light?
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;
}
}
}
}
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?
Hello,
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:
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
If there's anything else I can help you with, please let me know.
Best regards,
Edu
This should beprivate void Chart2_ClickLegend(object sender, Steema.TeeChart.Drawing.MouseEventArgs e)
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;
}
}
}
_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
Edu
Steema Support
Steema Support
-
- Newbie
- Posts: 9
- Joined: Fri Oct 22, 2021 12:00 am
Re: When you click the legend, series high light?
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
}
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
}
-
- Newbie
- Posts: 9
- Joined: Fri Oct 22, 2021 12:00 am
Re: When you click the legend, series high light?
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?
Hello,
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 there's anything else I can help you with, let me know!
Best regards,
Edu
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.// Error CS1061 'Legend' does not include a definition for 'ActiveStyle'.
Chart1.Legend.ActiveStyle = LegendActiveStyles.Opacity; 'ActiveStyle'. // Error
Chart1.Legend.ActiveStyle = LegendActiveStyles.LineThrough; // Error CS1061
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
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 you double-click on the items in the Legend box, all of those Legend items and chart series also disappear.
If there's anything else I can help you with, let me know!
Best regards,
Edu
Edu
Steema Support
Steema Support