willdale / SwiftUICharts

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

GroupedBarChart - Possible bug with the placement of the x axis labels #86

Closed imaaronath closed 3 years ago

imaaronath commented 3 years ago

Hi willdale , can you check the xAxislabels from GroupedBarChart ? In my app xAxis making bug like floating on the middle

willdale commented 3 years ago

Can you post some minimal, reproducible code? A Screenshot?

On a side note, can you change the title of the post to something more findable for others?

Thanks, Will

imaaronath commented 3 years ago

GroupedBarDataSet(dataPoints: [GroupedBarDataPoint(value: 20, description: "Q1", group: GroupingData(title: "A", colour: ColourStyle(colour: .red))),GroupedBarDataPoint(value: 40, description: "Q2", group: GroupingData(title: "A", colour: ColourStyle(colour: .red)))], setTitle: "Halo")]) IMG_9A55004E6DF2-1

willdale commented 3 years ago

I think the issue is to many labels in the y axis.

ChartStyle(...
           yAxisNumberOfLabels: 3
           ...
imaaronath commented 3 years ago

I'm sorry , I don't understand bcs my code

imaaronath commented 3 years ago

let data = GroupedBarDataSets(dataSets: [ GroupedBarDataSet(dataPoints: [GroupedBarDataPoint(value: 20, description: "Q1", group: GroupingData(title: "A", colour: ColourStyle(colour: .red))),GroupedBarDataPoint(value: 40, description: "Q2", group: GroupingData(title: "A", colour: ColourStyle(colour: .red)))], setTitle: "Halo")]) let group = [GroupingData(title: "A", colour: ColourStyle(colour: .red)),GroupingData(title: "B", colour: ColourStyle(colour: .blue)),GroupingData(title: "C", colour: ColourStyle(colour: .green))] let metadata = ChartMetadata(title: "US vs NON US", titleFont: .headline, titleColour: .black) let barStyle = BarStyle(barWidth: 0.95, colourFrom: .barStyle)

imaaronath commented 3 years ago

Before 2.6.4 everything is alright

willdale commented 3 years ago

Please see : https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown for how to format code when you post it.

Please post all of the GroupedBarChartData.

imaaronath commented 3 years ago
var finalData:GroupedBarChartData = data()            
GroupedBarChart(chartData: finalData, groupSpacing: 25)
                .touchOverlay(chartData: finalData)
                .xAxisGrid(chartData: finalData)
                .yAxisGrid(chartData: finalData)
                .xAxisLabels(chartData: finalData)
                .yAxisLabels(chartData: finalData)
                .infoBox(chartData: finalData)
                .floatingInfoBox(chartData: finalData)
                .headerBox(chartData: finalData)
                .legends(chartData: finalData)
static func data() -> GroupedBarChartData {
        let data = GroupedBarDataSets(dataSets: [
            GroupedBarDataSet(dataPoints: [
                                GroupedBarDataPoint(value: 20, description: "Q1", group: GroupingData(title: "A", colour: 
                                ColourStyle(colour: .red))),
                                GroupedBarDataPoint(value: 40, description: "Q2", group: GroupingData(title: "A", colour: 
                                ColourStyle(colour: .red)))],
                                setTitle: "Hello")
        ])
        let group = [GroupingData(title: "A", colour: ColourStyle(colour: .red)),
                     GroupingData(title: "B", colour: ColourStyle(colour: .blue)),
                     GroupingData(title: "C", colour: ColourStyle(colour: .green))]
         return GroupedBarChartData(dataSets: data, groups: group)
}

Edited to format the code properly. - Will

willdale commented 3 years ago
GroupedBarChartData(dataSets: data, groups: groups, chartStyle: BarChartStyle(yAxisNumberOfLabels: 3))
imaaronath commented 3 years ago

It's work thank you so much