willdale / SwiftUICharts

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.
MIT License
843 stars 105 forks source link

LineChart and BarChart combined? #108

Closed dsaliberti closed 3 years ago

dsaliberti commented 3 years ago

Hi 👋 I searched for it in the repo and couldn't find it and I'm still not sure if it's somehow possible. I need a combination of 2 chart types: line and bar. I imagine that I can try to achieve that by going purely on SwiftUI (maybe a ZStack) but wanted to check here.

side note: the demo project doesn't have an Xcode project (not sure if that was intentional)

Great work guys! Thanks ✨ Danilo

willdale commented 3 years ago

Hi, You could use a Bar Chart with .extraLine view modifier on it.

BarChart(chartData: data)
    .extraLine(chartData: data,
               legendTitle: "Test",
               datapoints: extraLineData,
               style: extraLineStyle)
    ... // some where down the chain
    .extraYAxisLabels(chartData: data, colourIndicator: .style(size: 12))
private var extraLineData: [ExtraLineDataPoint] {
    [ExtraLineDataPoint(value: 200),
     ExtraLineDataPoint(value: 90),
     ExtraLineDataPoint(value: 700),
     ExtraLineDataPoint(value: 175),
     ExtraLineDataPoint(value: 60),
     ExtraLineDataPoint(value: 100),
     ExtraLineDataPoint(value: 600)]
}
private var extraLineStyle: ExtraLineStyle {
    ExtraLineStyle(lineColour: ColourStyle(colour: .blue),
                   lineType: .curvedLine,
                   lineSpacing: .bar,
                   yAxisTitle: "Bob",
                   yAxisNumberOfLabels: 7,
                   animationType: .raise,
                   baseline: .zero)
}

Hmm, I'll have a look at the Demo Project.

Thanks, Will