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 for candlestick + bar #3262

Closed
royherma opened this issue Feb 12, 2018 · 4 comments
Closed

Combined chart for candlestick + bar #3262

royherma opened this issue Feb 12, 2018 · 4 comments

Comments

@royherma
Copy link

This seems to me like something pretty trivial to do, and I got it working on android but not on iOS, even after reading pretty thoroughly through previous issues and SO...

Anyhow, I'm simply trying to create a combined chart of historical price data that includes candlestick chart alongside volume indicators (bar charts) in the background. It comes out displaying like this:

image

Code is pretty straightforward and follows the example:

        let set1 = CandleChartDataSet(values: yVals1, label: "Data Set")
        set1.axisDependency = YAxis.AxisDependency.left
        set1.setColor(UIColor(white: 80 / 255, alpha: 1))
        set1.drawIconsEnabled = false
        set1.shadowColor = .darkGray
        set1.shadowWidth = 0.7
        set1.decreasingColor = .red
        set1.decreasingFilled = true
        set1.increasingColor = UIColor(red: 122 / 255, green: 242 / 255, blue: 84 / 255, alpha: 1)
        set1.increasingFilled = false
        set1.neutralColor = .blue
        set1.drawValuesEnabled = false
        self.candleStickChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: xValues)
        let candleStickData = CandleChartData(dataSet: set1)
        

        let data = CombinedChartData()
        let barChartDataSet = BarChartDataSet(values: barChartEntries, label: "values")
        barChartDataSet.setColor(UIColor.rhLightGrey().withAlphaComponent(0.3))
        barChartDataSet.axisDependency = YAxis.AxisDependency.right
        let barChartData = BarChartData(dataSet: barChartDataSet)
        
        data.candleData = candleStickData
        data.barData = barChartData
        
        self.candleStickChartView.rightAxis.axisMinimum = 0.0
        
        self.candleStickChartView.data = data
        self.candleStickChartView.setNeedsDisplay()

When I remove data.barData = barChartData it displays the candlestick fine, however I can't get the "scaling" to be dependent by the candlestick values (which are much lower) than the volume bars.

Any ideas?

Thanks!

@aelam
Copy link
Contributor

aelam commented Feb 13, 2018

Have you tried set chartView.autoScaleMinMaxEnabled = true?

@royherma
Copy link
Author

Just added it, didn't help @aelam

@royherma
Copy link
Author

any idea @aelam ? It looks like I can't get the bar-chart to plot against the right axis...

@royherma
Copy link
Author

Seemed like a clean + re-build worked for me doh

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