In wpf oxyplot, is there a way to make only the clicked item visible when the legend item is clicked?

JunYoungLee 161 Reputation points
2022-07-09T04:56:17.813+00:00

I made an oxyplot with wpf as below. If I click the line1 legend below, line1 will be invisible.
In addition to this function, I want to show only line1 when a specific key is pressed (ex. ctrl+mouse left btn) and hide the rest of the legend items.
But I'm not sure about the legend click event.
Can anyone help me? I am attaching my code and picture description.

219079-capture.png

xaml  
  
<Window x:Class="oxyplot_sample.MainWindow"  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
        xmlns:local="clr-namespace:oxyplot_sample"  
        mc:Ignorable="d"  
        xmlns:oxy="http://oxyplot.org/wpf"  
        Title="MainWindow" Height="450" Width="800">  
    <Grid>  
        <oxy:PlotView Model="{Binding plotmodel}" Margin="10 10 10 10"/>  
    </Grid>  
</Window>  


cs  
  
namespace oxyplot_sample  
{  
    /// <summary>  
    /// Interaction logic for MainWindow.xaml  
    /// </summary>  
    public partial class MainWindow : Window  
    {  
  
        public PlotModel plotmodel { get; set; }  
  
        public MainWindow()  
        {  
            InitializeComponent();  
                          
            plotmodel = new PlotModel();              
              
            var line1 = new LineSeries() { Title="line1"};  
            var line2 = new LineSeries() { Title="line2"};  
            var line3 = new LineSeries() { Title="line3"};  
  
            for (int i=0; i<10; i++)  
            {  
                line1.Points.Add(new DataPoint(i, i));  
                line2.Points.Add(new DataPoint(i, i + 1));  
                line3.Points.Add(new DataPoint(i, i + 2));  
            }              
  
            plotmodel.Series.Add(line1);  
            plotmodel.Series.Add(line2);  
            plotmodel.Series.Add(line3);  
            plotmodel.Legends.Add(new Legend()  
            {  
                LegendPosition = LegendPosition.TopCenter,  
                LegendFontSize = 15  
            }) ;  
  
            plotmodel.Axes.Add(new LinearAxis { Position = AxisPosition.Left});  
            this.DataContext = this;  
              
        }  
  
          
    }  
}  
Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | .NET Runtime
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.