Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
Interacting with legend
posted

Hi

 I'm trying to highlight a legend item if the user clicks on the series, and highlight a series if the user
clicks on the legend item it belongs too.

Is there some way I can do this? I'm unable to find the legend items added by default.

Parents
  • 28496
    Offline posted

    you can do this by handling the ChartDrawItem and ChartDataClicked events, as in this sample code

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    this.CurrentRow = -1;

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    this.ultraChart1.ChartType = ChartType.ColumnChart;

    this.ultraChart1.Legend.Visible = true;

    this.ultraChart1.ColorModel.ModelStyle = ColorModels.CustomSkin;

    this.ultraChart1.ColorModel.Skin.PEs.Add(new PaintElement(Color.Red));

    this.ultraChart1.ColorModel.Skin.PEs.Add(new PaintElement(Color.Green));

    this.ultraChart1.ColorModel.Skin.PEs.Add(new PaintElement(Color.Blue));

    this.ultraChart1.ColorModel.Skin.ApplyRowWise = true;

    this.ultraChart1.Data.DataSource = Infragistics.UltraChart.Data.DemoTable.Table();

    this.ultraChart1.ChartDrawItem += new Infragistics.UltraChart.Shared.Events.ChartDrawItemEventHandler(ultraChart1_ChartDrawItem);this.ultraChart1.ChartDataClicked += new ChartDataClickedEventHandler(ultraChart1_ChartDataClicked);

    }

    private int CurrentRow { get; set; }

     

    private void ultraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e)

    {

    if (e.Primitive.Path != null && e.Primitive.Path.IndexOf("Legend") != -1)

    {

    e.Primitive.Caps |=
    PCaps.HitTest;

    }

    if (this.CurrentRow != -1 && e.Primitive.Row == CurrentRow)

    {

    e.Primitive.PE =
    new PaintElement(Color.Yellow);

    }

    }

    private void ultraChart1_ChartDataClicked(object sender, ChartDataEventArgs e)

    {

    this.CurrentRow = e.Primitive.Row;this.ultraChart1.InvalidateLayers();

    }

    }

Reply Children