We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to know the number of point visible on a chart

Hello,

I have a chart with a several series (from 1 to 20 or more) and with a lot of points (can be more than a million).

I want to switch from FastLineBitmapSerie to FastLineSerie depending of the number of points on the chart for a better visual precision.
At the moment, I use the zoomFactor X * ZoomFactor Y to do it, for example I use FastLineBitmapSerie  if it is > 0.12 and FastLineSerie if  < 0.12.

It works but it is not accurate because depending of the number of series visible it has to be adjusted.

Is it possible to get the number of points plotted on the graph after zooming in or out, then it can be my condition to switch from one type of graph to another?
Is it possible to get the number of series visible on the graph after zooming in or out?

Thank you in advance
Best Regards
Nicolas


5 Replies

HM Hemalatha Marikumar Syncfusion Team January 9, 2020 01:30 PM UTC

Hi Nicolas, 
  
Greetings from Syncfusion. 
  
Query 1: Is it possible to get the number of points plotted on the graph after zooming in or out, then it can be my condition to switch from one type of graph to another? 
  
Yes. You can achieve this requirement with the help of GetDataPoints method in FastLineBitmapSeries. This method returns the collection of datapoints which is available in chart area, based on the given parameters. Please refer below code snippet. 
  
Code Snippet [C#]: 
private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            foreach (var series in chart.Series) 
            { 
                List<object> data; 
                if (series is FastLineBitmapSeries) 
                { 
                    //You can get the corresponsing series datapoints using GetDataPoints method. 
                    data = (series as FastLineBitmapSeries).GetDataPoints(primaryAxis.VisibleRange.Start, primaryAxis.VisibleRange.End, secondaryAxis.VisibleRange.Start, secondaryAxis.VisibleRange.End); 
                    //You can get the visible datapoints count by using the list. 
                    int dataCount = data.Count; 
                } 
                
            }            
 } 
  
  
Query 2: Is it possible to get the number of series visible on the graph after zooming in or out? 
  
Yes. You can achieve this requirement with GetDataPoints method itself. It will return the collection of datapoints only if the series is visible, else it will return the empty list for the corresponding series. Based on this you can get the visible series in chart by counting the series as per in the below code snippet. 
  
Code Snippet [C#]: 
private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            int seriescount = 0; 
            foreach (var series in chart.Series) 
            { 
                List<object> data; 
                if (series is FastLineBitmapSeries) 
                { 
                    data = (series as FastLineBitmapSeries).GetDataPoints(primaryAxis.VisibleRange.Start, primaryAxis.VisibleRange.End, secondaryAxis.VisibleRange.Start, secondaryAxis.VisibleRange.End); 
                    
                    int dataCount = data.Count; 
                    seriescount = dataCount > 0 ? seriescount + 1 : seriescount; 
                } 
                
            } 
  
            Console.WriteLine("VisibleSeries count is " + seriescount.ToString());        
} 
  
And we have prepared a sample based on your requirement and you can download the sample from the below link. 
  
  
Please let us know if need any further assistance on this. 
 
Regards, 
Hemalatha M. 



NI Nicolas January 9, 2020 07:50 PM UTC

Thank you for your reply,

you're example works well if all series use the secondary axis.
My chart is associated with series from a datatable, data come from CSV file.
I use one Yaxis for each serie. I use the secondary axis for another purpose.

Then if I have 10 series, I will have 10 different Y axis with different scales.
I don't know in advance how many series I will have, it depends from the CSV file.

All series uses primary axis as a datetime axis.

I can't find the right syntax to select the corresponding serie axis for each serie instead of secondary axis.

Thank you in advance for your help
Regards
Nicolas





LA Lavanya Anaimuthu Syncfusion Team January 10, 2020 08:57 AM UTC

Hi Nicolas, 
 
Thanks for the update. 
 
Query: I can't find the right syntax to select the corresponding series axis for each series instead of secondary axis. 
 
You can also get the corresponding series y-axis by using YAxis property in FastLineBitmapSeries as per in the below code snippet. 
 
Code Snippet [C#]:  
foreach (var series in chart.Series) 
     { 
               DoubleRange xAxisRange = primaryAxis.VisibleRange; 
                List<object> data; 
 
                if (series is FastLineBitmapSeries) 
                { 
                    FastLineBitmapSeries fastLineBitmap = series as FastLineBitmapSeries; 
                   DoubleRange yAxisRange = fastLineBitmap.YAxis.VisibleRange; 
 
                    data = fastLineBitmap.GetDataPoints(xAxisRange.Start, xAxisRange.End, yAxisRange.Start, yAxisRange.End); 
                   } 
       } 
 
Please let us know if need any further assistance on this issue. 
 
Thanks, 
Lavanya A. 
 



NI Nicolas January 15, 2020 12:40 PM UTC

Thank you very much for your help.

It works exactly as I want.

Best Regards
Nicolas


LA Lavanya Anaimuthu Syncfusion Team January 16, 2020 04:16 AM UTC

Hi Nicolas, 
 
Thanks for your update.  
  
We are glad to hear that given solution works.  
  
Please let us know if you need any further assistance. 
 
Thanks, 
Lavanya A. 


Loader.
Live Chat Icon For mobile
Up arrow icon