willdale / SwiftUICharts

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

Multiline chart with different amounts of points not working #214

Open dadixon opened 2 years ago

dadixon commented 2 years ago

I have a multiple line chart working from the demo but the graph I need to create has 1 line with 12 points and another with only 8. When I try this, the shorter graph is stretched and I don't want this behavior. Is that possible?

dadixon commented 2 years ago

let data = MultiLineDataSet(dataSets: [ LineDataSet( dataPoints: [ LineChartDataPoint(value: 4.3, xAxisLabel: "7/13", description: "Saturday, July 9, 00:00 GMT"), LineChartDataPoint(value: 4.5, xAxisLabel: "F", description: "February"), LineChartDataPoint(value: 6.9, xAxisLabel: "M", description: "March"), LineChartDataPoint(value: 8.7, xAxisLabel: "A", description: "April"), LineChartDataPoint(value: 12.1, xAxisLabel: "M", description: "May"), LineChartDataPoint(value: 15.1, xAxisLabel: "J", description: "June"), LineChartDataPoint(value: 17.3, xAxisLabel: "J", description: "July"), LineChartDataPoint(value: 17.0, xAxisLabel: "A", description: "August"), LineChartDataPoint(value: 14.3, xAxisLabel: "S", description: "September"), LineChartDataPoint(value: 10.9, xAxisLabel: "O", description: "October"), LineChartDataPoint(value: 7.2, xAxisLabel: "N", description: "November"), LineChartDataPoint(value: 4.7, xAxisLabel: "D", description: "December") ], legendTitle: "Predictions", pointStyle: PointStyle(pointType: .outline, pointShape: .circle), style: LineStyle(lineColour: ColourStyle(colour: .orange), lineType: .line) ), LineDataSet( dataPoints: [ LineChartDataPoint(value: 16.9, xAxisLabel: "J", description: "January"), LineChartDataPoint(value: 17.2, xAxisLabel: "F", description: "February"), LineChartDataPoint(value: 15.8, xAxisLabel: "M", description: "March"), LineChartDataPoint(value: 13.7, xAxisLabel: "A", description: "April"), LineChartDataPoint(value: 11.7, xAxisLabel: "M", description: "May"), LineChartDataPoint(value: 9.7, xAxisLabel: "J", description: "June"), LineChartDataPoint(value: 8.9, xAxisLabel: "J", description: "July") ], legendTitle: "Preliminary", pointStyle: PointStyle(pointType: .outline, pointShape: .square), style: LineStyle(lineColour: ColourStyle(colour: .blue), lineType: .line) ) ])

produces

Screen Shot 2022-07-14 at 6 45 32 AM