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;  
              
        }  
  
          
    }  
}  
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,755 questions
C#
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.
10,819 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,151 questions
{count} votes

1 answer

Sort by: Most helpful
  1. dinozee 1 Reputation point
    2022-07-11T10:12:31.32+00:00

    We're a print-on-demand company that specializes in unique, custom designs. We believe that the best product is one that's just for you. That's why, when you shop with us, we'll make sure to give you the attention and service you deserve.

    ADD: 14801 Able Ln, Ste 102 Huntington Beach, CA 92647, United States

    Email: dinozeetee@Stuff .com

    Website: https://dinozee.com/

    0 comments No comments

Your answer

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