Sonntag, 19. Juli 2015

Multiline chart, now with less code

I started adding some convenience classes to SwiftCharts to create popular charts quickly.

This is how now a multiline chart is created:

let chart = LineChart(
    frame: CGRectMake(0, 70, 300, 500),
    chartConfig: ChartConfig(
        xAxisConfig: ChartAxisConfig(from: 2, to: 14, by: 2),
        yAxisConfig: ChartAxisConfig(from: 0, to: 14, by: 2)
    ),
    xTitle: "X axis",
    yTitle: "Y axis",
    lines: [
        (chartPoints: [(2.0, 10.6), (4.2, 5.1), (7.3, 3.0), (8.1, 5.5), (14.0, 8.0)], color: UIColor.redColor()),
        (chartPoints: [(2.0, 2.6), (4.2, 4.1), (7.3, 1.0), (8.1, 11.5), (14.0, 3.0)], color: UIColor.blueColor())
    ]
)
self.view.addSubview(chart.view)

Of course the "low level" api and examples continue to be available, and should be used when the convenience charts don't provide the required level of customization.

More will follow!

Kommentare:

  1. Hi - I'm just starting to use SwiftCharts. I tried using the above example to create a multiline chart. I can see the chart, but the axis titles are not drawn and neither are the labels that should be shown on each axis. Any idea why I'm only seeing the two lines and not the axis information. Please let me know what I need to do in order to fix this.

    Thanks,
    Howie

    AntwortenLöschen
  2. You probably are missing to retain the chart in an instance variable... take a look here https://github.com/i-schuetz/SwiftCharts/issues/54 (next to last comment) for more details.

    AntwortenLöschen