How to select Chart-Serie by Name or ID


Author
Message
joern kunze
joern kunze
Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)
Group: Forum Members
Posts: 86, Visits: 221
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





Reply
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

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.



Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search