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

yAxis label shows only when i touch the view #618

Closed
zhmiblog opened this issue Dec 18, 2015 · 6 comments
Closed

yAxis label shows only when i touch the view #618

zhmiblog opened this issue Dec 18, 2015 · 6 comments

Comments

@zhmiblog
Copy link

I used the lineChartView to draw a line chart, But I run out an issue: My yAxis label doesn't show anyway with codes below, only when I touch it to highlight something, the label shows. how can I show it instantly at the beginning?

    lineChartView.descriptionText = ""
    lineChartView.gridBackgroundColor = UIColor.whiteColor()
    lineChartView.legend.enabled = true
    lineChartView.dragEnabled = false
    lineChartView.doubleTapToZoomEnabled = false
    lineChartView.pinchZoomEnabled = true
    lineChartView.autoScaleMinMaxEnabled = true

    lineChartView.rightAxis.enabled = false
    lineChartView.leftAxis.startAtZeroEnabled = false
    lineChartView.leftAxis.gridLineWidth = 0.1
    lineChartView.leftAxis.drawAxisLineEnabled = false
    lineChartView.leftAxis.drawLabelsEnabled = true
    lineChartView.xAxis.labelPosition = .Bottom
    lineChartView.xAxis.drawAxisLineEnabled = false
@zhmiblog
Copy link
Author

Who can help me to solve this problem?Many Thanks......

@liuxuan30
Copy link
Member

Can you reproduce it with ChartsDemo code?
It will show up by default because drawLabelsEnabled is true if you don't change it.

I do see you call lineChartView.leftAxis.drawLabelsEnabled = true. Are you using leftAxis or rightAxis? By default it's left. Also, dataSet has a propety called axisDependency, have you changed it?

@zhmiblog
Copy link
Author

@liuxuan30 , I tried ChartsDemo with replacing the chart-setting code,And the label didn't show either. In my code,I put all chart-setting work in a func, maybe you can run it in xcode simply if you kindly help to solve.For your question, I use leftAxis, and I didn't change dataSet's attribute axisDependency.
code as below:

    func setChart(var dataPoints: [String],lineChartView: LineChartView, values: [Double],Date: String) {
        lineChartView.noDataText = "You need to provide data for the chart."
        var dataEntries: [ChartDataEntry] = [] 
        for i in 1..<dataPoints.count {
            let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
            dataEntries.append(dataEntry)
        }
        dataPoints.removeFirst()
        let chartDataSet = LineChartDataSet(yVals: dataEntries, label: Date)
        let chartData = LineChartData(xVals: dataPoints, dataSet: chartDataSet)
        lineChartView.data = chartData

        chartDataSet.drawCircleHoleEnabled = true
        chartDataSet.drawValuesEnabled = false
        chartDataSet.drawFilledEnabled = false
        chartDataSet.drawCirclesEnabled = false
        chartDataSet.lineWidth = 1.0
        //        chartDataSet.colors = [UIColor.init(red: 74/255, green: 134/255, blue: 232/255, alpha: 1)]

        lineChartView.descriptionText = ""
        lineChartView.gridBackgroundColor = UIColor.whiteColor()
        lineChartView.legend.enabled = true
        lineChartView.dragEnabled = false
        lineChartView.doubleTapToZoomEnabled = false
        lineChartView.pinchZoomEnabled = true
        lineChartView.autoScaleMinMaxEnabled = true

        lineChartView.rightAxis.enabled = false
        lineChartView.leftAxis.gridLineWidth = 0.1
        lineChartView.leftAxis.startAtZeroEnabled = false
        lineChartView.leftAxis.drawAxisLineEnabled = false
        lineChartView.leftAxis.drawLabelsEnabled = true
        lineChartView.leftAxis.customAxisMax = Sigma.max(values)!
        lineChartView.leftAxis.customAxisMin = Sigma.min(values)!
        lineChartView.xAxis.labelPosition = .Bottom
        lineChartView.xAxis.drawGridLinesEnabled = false
        lineChartView.xAxis.drawAxisLineEnabled = false

        let ll = ChartLimitLine(limit: values[0], label: "zero line")
        ll.lineColor = UIColor.greenColor()
        ll.lineWidth = 1.0
        ll.labelPosition = .RightTop
        ll.valueFont = UIFont.boldSystemFontOfSize(10)
        lineChartView.leftAxis.addLimitLine(ll)


    }

@liuxuan30
Copy link
Member

As I said, ChartsDemo is totally free from your issue. Would you please post the code you tried in ChartDemo that can reproduce? I don't have a swift one in my hand.

BTW, from you code, I suspect it's because you first setup the data, then called lineChartView.data = chartData and then you start setting the chart, especially customAxisMax. What is Sigma.max(values)! ?

I would suggest put lineChartView.data = chartData into the last line. Or you call notifyDataSetChanged after you finish setting.

notifyDataSetChanged is called in chart data setter. That's why I said put it at last line.

A normal workflow is setting chart property -> feed data, because the chart setting will impact the axis and space calculating

If you still have the issue, please post the code that I can try in ChartsDemo. A screenshot is also helpful to understand.

@zhmiblog
Copy link
Author

@liuxuan30 as your advice,I put lineChartView.data = chartData on the tail,It worked. TTTTTThank U, master!
BTW, Sigma.max(values)! is fetching the max value of an array with another library about math, Couse there is lots of math works in my project.

@liuxuan30
Copy link
Member

NP :)

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

2 participants