AppPear / ChartView

ChartView made in SwiftUI
MIT License
5.35k stars 653 forks source link

Bars not displayed with form: ChartForm.large #70

Open DominikButz opened 4 years ago

DominikButz commented 4 years ago

Hi, great library ! However, I have noticed that the bar chart is empty when I set the form to large. It works with small and medium though.
Screenshots below. It is normal for my chosen data source that there are only two bars, the other bars have the value 0, that's why they are not shown. However, there should be two bars and not 0 like in the large chart.

Medium:

BarChartView(data: self.chartData, title: "Workouts Per Week", legend: "Date: start of each week", form: ChartForm.medium, dropShadow: false, valueSpecifier: "%.0f")

Screenshot 2020-05-01 at 19 46 40

Large:

BarChartView(data: self.chartData, title: "Workouts Per Week", legend: "Date: start of each week", form: ChartForm.large, dropShadow: false, valueSpecifier: "%.0f")

Screenshot 2020-05-01 at 19 45 30

The data I pass in for both chart sizes is exactly the same... Also, I think a relatively short title like "Workouts per Week" should not be truncated.

It should be possible to set the corner image to nil. if I try that, the app crashes.

thanks for your help

DominikButz commented 4 years ago

I just tried out your example TestChartViews. The problem must be in the ChartData object. If I change your example to form: ChartForm.large, while keeping the data points the same as in your example, the bars are displayed as expected.

This works as expected: BarChartView(data: ChartData(points: [8,23,54,32,12,37,7,23,43]), title: "Title", style: Styles.barChartStyleOrangeLight, form: ChartForm.large)

Screenshot 2020-05-02 at 11 07 22

Once I change the ChartData to a tuple array, ChartForm.large does not display any bars:

BarChartView(data: ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900), ("2019 Q2",77550), ("2019 Q3",79600), ("2019 Q4",92550)]), title: "Title", style: Styles.barChartStyleOrangeLight, form: ChartForm.large)

Screenshot 2020-05-02 at 11 09 38
DominikButz commented 4 years ago

I have created a fork with a new branch called ignoreFormSizeHeight. I added a new property ("ignoreFormSizeHeight") to the initialiser (default is false). this seems to fix the bug because now I can set a frame height like this:

BarChartView(data: ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900), ("2019 Q2",77550), ("2019 Q3",79600), ("2019 Q4",92550)]), title: "Title", style: Styles.barChartStyleOrangeLight, form: ChartForm.large, ignoreFormSizeHeight: true).frame(height: 300)

it seems the default height for iOS when ChartForm is large - 120 - is too narrow for the bars to appear... not sure why this works with ChartData values as points...).

another possibility is to set an explicit relative height to BarChartRow like this: frame(height: self.formSize.height * 0.9)

Screenshot 2020-05-03 at 17 59 57