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

Combined chart (Scatter and Line) producing random results. #4261

Closed
cnnamoca opened this issue Jan 9, 2020 · 1 comment
Closed

Combined chart (Scatter and Line) producing random results. #4261

cnnamoca opened this issue Jan 9, 2020 · 1 comment

Comments

@cnnamoca
Copy link

cnnamoca commented Jan 9, 2020

What did you do?

Create a combined Scatter and Line Chart.

What did you expect to happen?

I wanted the line to be behind the scatter plot.

What happened instead?

It actually works but for some reason, it sometimes produces the image attached randomly and I would have to restart the app or reload the view every time.

Charts Environment

3.4.0 / master
Xcode 11.2.1
Swift 5
iOS
macOS 10.15.1

Demo Project

func createCombinedChart(_ values1: [ChartDataEntry], _ values2: [ChartDataEntry], _ chartView: CombinedChartView, _ chartType: ChartType, _ isLinear: Bool, _ hasGradient: Bool) {
        
        let set1 = ScatterChartDataSet(entries: values1, label: nil)
        set1.highlightEnabled = true
        set1.highlightColor = .clear // Removes orange lines from marker
        set1.drawValuesEnabled = false
        set1.setScatterShape(.circle)
        set1.scatterShapeSize = 6.0
        set1.setColor(UIColor.white)
        
        let set2 = LineChartDataSet(entries: values2, label: nil)
        set2.highlightEnabled = false
        set2.highlightColor = .clear // Removes orange lines from marker
        set2.drawValuesEnabled = false
        set2.drawCirclesEnabled = false
        set2.circleRadius = 0.5
        set2.lineCapType = .round
        set2.lineWidth = 1
        set2.lineDashLengths = [5, 5]
        set2.mode = isLinear ? .linear : .cubicBezier
        set2.colors = [NSUIColor(named: "Purple_02")] as! [NSUIColor]
        
        let gradientColors = [UIColor.clear.cgColor, UIColor(named: "Purple_01")!.cgColor]
        let gradient = CGGradient(colorsSpace: nil, colors: gradientColors as CFArray, locations: nil)!
        
        set2.fillAlpha = 1
        set2.fill = Fill(linearGradient: gradient, angle: 90)
        set2.drawFilledEnabled = hasGradient
        
        chartView.leftAxis.drawGridLinesEnabled = true
        chartView.leftAxis.drawAxisLineEnabled = true
        chartView.leftAxis.drawLabelsEnabled = true
        chartView.leftAxis.labelFont = UIFonts.BOLD_FONT_EXTRA_SMALL
        chartView.leftAxis.labelTextColor = .white
        chartView.leftAxis.axisLineColor = .darkGray
        chartView.leftAxis.axisMinimum = 0 // Keeps the x and y minimum values on the same axis
        
        chartView.rightAxis.enabled = false
        
        chartView.xAxis.drawGridLinesEnabled = false
        chartView.xAxis.drawAxisLineEnabled = true
        chartView.xAxis.drawLabelsEnabled = true
        chartView.xAxis.labelFont = UIFonts.BOLD_FONT_EXTRA_SMALL
        chartView.xAxis.labelTextColor = .white
        chartView.xAxis.labelPosition = .bottom
        chartView.xAxis.axisLineColor = .darkGray
        chartView.xAxis.avoidFirstLastClippingEnabled = true
        
        chartView.legend.enabled = false
        chartView.chartDescription?.enabled = true
        chartView.chartDescription?.textColor = .white
        chartView.chartDescription?.font = UIFonts.BOLD_FONT_EXTRA_SMALL
        chartView.chartDescription?.text = "→ \(getAxes(chartType).x), ↑ \(getAxes(chartType).y)"
        chartView.doubleTapToZoomEnabled = false
        chartView.pinchZoomEnabled = false
                
        let data = CombinedChartData()
        data.scatterData = ScatterChartData(dataSets: [set1])
        data.lineData = LineChartData(dataSets: [set2])
        data.notifyDataChanged()
        chartView.data = data
        chartView.notifyDataSetChanged()
    }

Image from iOS

@liuxuan30
Copy link
Member

liuxuan30 commented May 12, 2020

I suppose your x values are not sorted

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