Nevron Forum

How to select Chart-Serie by Name or ID

https://www.nevron.com/Forum/Topic5905.aspx

By joern kunze - Thursday, December 1, 2011

Hi Experts,
Is there a way to get an existing point-series of a chart by name or ID (and check in the first place, if a series with that name does exist at all)?

I get the name / id within e.g. a mouse move event:
... ((NSeriesBase)hitTestResult.Object.ParentNode).Name;
... ((NSeriesBase)hitTestResult.Object.ParentNode).Id;

Now I want to remember just the name / id in case I have to change series properties later.
I am looking now for a way to retrieve the serie by name (or ID) something like:
if( _NevronChart.Chart[0].DoesSeriesExist(m_sNameOfSeries) {
NPointSeries series = _NevronChart.Chart[0].GetSeries(m_sNameOfSeries)....
}

Thanks for your help,
Joern




By Nevron Support - Thursday, December 1, 2011

Hi Joern,

You can look for chart elements by their unique id - it will stay the same even if the document is serialized / deserialized:


        Guid m_LastClickedSeriesId;

            NChart chart = nChartControl1.Charts[0];

            NBarSeries bar1 = new NBarSeries();
            bar1.Values.Add(10);
            bar1.Values.Add(20);
            bar1.Values.Add(30);
            chart.Series.Add(bar1);

            NBarSeries bar2 = new NBarSeries();
            bar2.Values.Add(10);
            bar2.Values.Add(20);
            bar2.Values.Add(40);
            bar2.MultiBarMode = MultiBarMode.Clustered;
            chart.Series.Add(bar2);

            nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
            nChartControl1.Refresh();


        void nChartControl1_MouseDown(object sender, MouseEventArgs e)
        {
            NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

            if (result.ChartElement == ChartElement.DataPoint)
            {
                m_LastClickedSeriesId = result.Series.UniqueId;
            }
        }

        private void HighlightLastClickedBar()
        {
            NBarSeries series = nChartControl1.Document.GetElementFromUniqueId(m_LastClickedSeriesId) as NBarSeries;

            if (series != null)
            {
                series.FillStyle = new NColorFillStyle(Color.Red);
                nChartControl1.Refresh();
            }
        }

The above example shows how to store the unique id of the last clicked series and then to search / highlight.

Hope this helps - let us know if you meet any problems.

By joern kunze - Monday, December 5, 2011

.. thanks a lot! Just one tiny problem remains:
How do I get the serie topmost (so that it is displayed over all other series)?

Thanks again,
Joern
By Nevron Support - Monday, December 5, 2011

Hi Joern,

That's easy - you just need to make the series the first one in the series collection (e.g. change it position there).

By joern kunze - Tuesday, December 6, 2011

... thanks for the hint. Unfortunatly, it is not quite the solution for my problem. I have already done it this way - but running into performance issues with that:
I have about 2000 series with about 70 000 data points each. Now the customer wants to select some serties for highlighting -> and this is rather slow (we "compete" against a compiled MATLAB-application with data visualisation which has the same data loaded).
Presently I always use - as proposed -
nChartControl1.Refresh();
after the series has been selected into the MouseMoveEvent for highlighting.
I was sort of hoping that there is another - faster - way of bringing the selected series topmost (may be without having to redraw the entire chart with 2000 series)

Best regards,
Joern
By Nevron Support - Wednesday, December 7, 2011

Hi Joern,

In this case you may consider to prerender the line series and paint them on the control as pre-rasterized. The advantage here is that this can be done in multithread fashion etc, however writing this type of code is beyond the service we provide on the forum...