ivnsch / SwiftCharts

Easy to use and highly customizable charts library for iOS
Apache License 2.0
2.53k stars 408 forks source link

Is't possible to make MultiAxis scrollable graph using this? #224

Closed punithbm closed 7 years ago

punithbm commented 7 years ago

Hi,

Thanks for such a great library. I would like to know whether it's possible to make multi axis scroll view like this - https://github.com/philackm/Scrollable-GraphView

Cause the above link i sent you supports only single line graph. Is't possible to make like that with multiple linegraphs using this. It'll be great helpful for us

ivnsch commented 7 years ago

What do you exactly mean with "like this"?

You can show a (finite) multi-axis scrollable line chart, yes. You can use master and set an initial zoom value that produces the desired width.

Ignore the scrollable example in the current release version, this doesn't perform well with not-small datasets and will be removed in the next release.

The animations I see there are not supported though. But can be implemented, with some effort.

If you try it out let me know how it goes. The lines are current re-drawn on each zoom/pan delta so I could imagine performance issues for very large datasets, but this is something we/I can work on to optimize (not re-drawing the line for panning should be enough). You also shouldn't use dotted guidelines as they consume a lot of performance (the library you link to also doesn't use them, probably because of this).

punithbm commented 7 years ago

Hi @i-schuetz thanks a lot.. Thank you..

But I'm not looking for any animations like that. I'm just looking for scrollable graph view where i can draw multiple lines and scroll at the same.. As you mention we can set it through zoom value. Can you help me out in this.

I've attached a screen shot .. That's what i needed.. If you can help me that would be really great ` screen shot 2017-02-19 at 7 06 02 pm

ivnsch commented 7 years ago

I adjusted one of the examples to show how to set the initial zoom level / scroll area. Also added some explanations.

To use master, you need this in your podfile:

pod 'SwiftCharts', :git => 'https://github.com/i-schuetz/SwiftCharts.git'

Let me know how it goes! Happy to continue assisting to get your chart working. The zooming api is still a bit unpolished and it requires sometimes non-obvious steps.

punithbm commented 7 years ago

Hi @i-schuetz thanks for spending your valuable time spending over my problem..

I did try with your example .. and it works like charm .. but i wanted multiple line with dots unfortunately.. now i was able to create one line graph with the link i mentioned you earlier.. so is it possible to do like that in this also?

ivnsch commented 7 years ago

If you look at the code you'll notice that you can pass an array of lines to the line layer:

let chartPointsLineLayer = ChartPointsLineLayer(xAxis: xAxisLayer.axis, yAxis: yAxisLayer.axis, lineModels: [lineModel], delayInit: true)

For the dots you can use a ChartPointsViewsLayer, which you can copy-paste from Hello world example, and adjust to generate dots instead of labels.

Edit:

Actually there's an example that uses dots - you can replace the generator from "Hello world" with this:

let circleViewGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsLayer, chart: Chart, isTransform: Bool) -> UIView? in
    let color = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1)
    let circleView = ChartPointEllipseView(center: chartPointModel.screenLoc, diameter: 6)
    circleView.animDuration = isTransform ? 0 : 0.5
    circleView.fillColor = color
    return circleView
}

You can concatenate the chart points of all the lines together to pass them to the dots layer. Alternatively you can create one dots-layer per line, whatever suits your needs best.