2

Am trying to use the ios-charts library based off the MPAndroidCharts; however am having some trouble getting a scrollable graph to work.

By scrollable I mean that I try to show only a portion of the data of the line and that you can scroll horizontally to see more results. E.g I have 30 results and I only show 10 at a time and then scroll horizontally to see more.

Have come up with an approximation by using the method

[self.containerView setVisibleXRangeWithMinXRange:24.0f maxXRange:24.0f];

However this seems to make the scrolling kind of jittery as it keeps on redrawing.

Am looking for an ios-charts example and clarification on methods to see whether I am on the right track or not.

Pao13
  • 69
  • 1
  • 3

1 Answers1

7

Similar to your question:

https://github.com/danielgindi/ios-charts/issues/267

Quote:

I was able to achieve this after playing with it a bit. It is actually pretty straight forward.

chart.data = data; // This is the MAIN reason, data for the chart has to be set first before the next 2 steps otherwise they will just get ignored like nothing has been set.

// set the max x data point to 10, which is what i wanted showing only 10 data points for the line or bar chart, from 100 data points. [chart setVisibleXRangeMaximum:10]; // move the chart view to 90 index of X, which is the last 10 entries I want to see. and it works as expected. [chart moveViewToX:90];

Other helpful ones:

https://github.com/danielgindi/ios-charts/issues/226

https://github.com/danielgindi/ios-charts/issues/258

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • Thanks for the prompt reply, however my issue is not necessarily choosing which values to display initially, e.g 5-7 initially visible from set of 0-10, but that when I scroll; the scrolling seems choppy. while debugging; I noticed that it keeps on jumping to the drawRect method of the chart and redraws everything constantly. – Pao13 Aug 19 '15 at 03:21
  • yeah it will call drawRect by design – Wingzero Aug 19 '15 at 03:56
  • Have you also encountered a small performance hiccup during scroll? I am actually aiming to make the animation smooth; One idea I am thinking of is rendering the entire graph already; then putting it in a smaller scroll view. Am open to ideas and suggestions. – Pao13 Aug 19 '15 at 06:31
  • I don't have scroll lagging given ~1000 y values as line chart. scroll is smooth. I am not sure what animation you want to do, but scroll and animation is different. I guess there would be performance issue if you want to animate drawing the line or bar charts. – Wingzero Aug 19 '15 at 06:39
  • Another way is to use a mask view acting as the animation view if you have huge data sets. but for scrolling, I don't have problems. – Wingzero Aug 19 '15 at 06:40