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

CandleStick fill colors not showing #2742

Closed
Vaestro opened this issue Aug 21, 2017 · 5 comments
Closed

CandleStick fill colors not showing #2742

Vaestro opened this issue Aug 21, 2017 · 5 comments

Comments

@Vaestro
Copy link

Vaestro commented Aug 21, 2017

I am trying to present financial data in a CandleStick chart with the increasing fill color being green and the decreasing fill color being red. However the resulting chart ends up looking like this: https://s3.amazonaws.com/pearlventures/Screen+Shot+2017-08-21+at+6.37.24+PM.png

And here is the code concerning the chart:

override func viewDidLoad() {
    super.viewDidLoad()
    lineChartView = CandleStickChartView()
    let xAxis: XAxis? = lineChartView?.xAxis
    xAxis?.drawAxisLineEnabled = false
    xAxis?.drawGridLinesEnabled = false
    lineChartView?.leftAxis.enabled = false
    lineChartView?.rightAxis.enabled = false
    lineChartView?.legend.enabled = false
    lineChartView?.backgroundColor = .black
    lineChartView?.autoScaleMinMaxEnabled = true
    lineChartView?.noDataText = "No data"
    lineChartView?.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce)
    lineChartView?.delegate = self
    lineChartView?.pinchZoomEnabled = false
  
    contentView.addSubview(lineChartView!)
    lineChartView?.snp.makeConstraints { (make) in
      make.top.equalTo(priceChangeLabel.snp.bottom)
      make.right.left.equalToSuperview()
      make.height.equalTo(200)
    }
}
func updateLineGraph() {
   var candleChartEntry = [CandleChartDataEntry]()
   for histo in histoArray {
     let histoValue = CandleChartDataEntry.init(x: histo.timestamp, shadowH: histo.high, shadowL: histo.low, open: histo.open, close: histo.close)
     candleChartEntry.append(histoValue)
   }
   let candle1 = CandleChartDataSet.init(values: candleChartEntry, label: "Candle")
   candle1.axisDependency = .left
   candle1.setColor(UIColor(white: 80 / 255.0, alpha: 1.0))
   candle1.drawIconsEnabled = false
   candle1.shadowColor = NSUIColor.darkGray
   candle1.shadowWidth = 1.5
   candle1.decreasingColor = NSUIColor.red
   candle1.decreasingFilled = true
   candle1.increasingColor = NSUIColor(red: 122 / 255.0, green: 242 / 255.0, blue: 84 / 255.0, alpha: 1.0)
   candle1.increasingFilled = false
   candle1.showCandleBar = true
   candle1.neutralColor = NSUIColor.blue
   candle1.drawValuesEnabled = false
   
   
   let candleData = CandleChartData()
   candleData.addDataSet(candle1)
   lineChartView?.data = candleData
 }

@Vaestro Vaestro changed the title CandleStick bars not showing CandleStick fill colors not showing Aug 22, 2017
@liuxuan30
Copy link
Member

Have you checked ChartsDemo?

@Vaestro
Copy link
Author

Vaestro commented Aug 28, 2017

Yes @liuxuan30 I followed everything in the CandleStickChartViewController.m file

@liuxuan30
Copy link
Member

Can you at least draw the same candles like ChartsDemo? It's really not easy to know what happened with your code.

@Vaestro
Copy link
Author

Vaestro commented Aug 29, 2017

Just figured out the issue was because my x values were too big. I was trying to use timestamps as my x values and when I changed the x values to indexes of the array, the candles started to show properly.

@joeblau
Copy link

joeblau commented Jan 30, 2022

Just ran into this same problem 😂

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

3 participants