Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bar Chart legend always show one label #3462

Closed
devssun opened this issue May 18, 2018 · 1 comment
Closed

bar Chart legend always show one label #3462

devssun opened this issue May 18, 2018 · 1 comment

Comments

@devssun
Copy link

devssun commented May 18, 2018

What did you do?

ℹ Please replace this with what you did.
Hello, I use this library for bar Chart.
I want show legend equal bar chart data count. bar is show nice, but legend label is just show one label.
many googling but I can't found it.
plz how can I show legend label equal bar data count?

What did you expect to happen?

ℹ Please replace this with what you expected to happen.

What happened instead?

if I show bar data 4, then legend show 4
◼︎ data1 ◼︎ data2 ◼︎ data3 ◼︎ data4

ℹ Please replace this with of what happened instead.

Charts Environment

Charts version/Branch/Commit Number: 3.0.3
- Xcode 9 and Swift 3.2 support Version
Xcode version: 9.2
Swift version: 3.2
Platform(s) running Charts: iOS 10
macOS version running Xcode: 10.12.6

Demo Project

ℹ Please link to or upload a project we can download that reproduces the issue.
breedStatusChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: (showChartData["key"]?.displayName)!)

func setBarCharts(dataPoints: [String], values: [Double]) -> BarChartData {
        var dataEntries: [ChartDataEntry] = []
        for i in 0..<dataPoints.count {
            let dataEntry = BarChartDataEntry(x: Double(i), y: values[i])
            dataEntries.append(dataEntry)
        }
        
        let barChartDataSet = BarChartDataSet(values: dataEntries, label: nil)
        barChartDataSet.colors = tempColor()
        
        let barChartData = BarChartData(dataSet: barChartDataSet)
        barChartData.barWidth = 0.6
        
        let pFormatter = NumberFormatter()
        pFormatter.numberStyle = .none
        pFormatter.maximumFractionDigits = 1
        pFormatter.multiplier = 1
        barChartData.setValueFormatter(DefaultValueFormatter(formatter: pFormatter))
        barChartData.setValueFont(.systemFont(ofSize: 12))
        barChartData.setValueTextColor(.black)
        return barChartData
    }
@devssun
Copy link
Author

devssun commented May 21, 2018

I solved like this

var dataEntries: [BarChartDataSet] = []
        
        for i in 0..<dataPoints.count {
            let dataEntry = BarChartDataSet(values: [BarChartDataEntry(x: Double(i), y: values[i])], label: dataPoints[i])
            dataEntry.colors = [barColor[i]]
            dataEntries.append(dataEntry)
        }
        
        let barChartData = BarChartData(dataSets: dataEntries)

@devssun devssun closed this as completed May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant