How to draw custom views on top and bottom of the candle in candlestick chart

329 Views Asked by At

I am using the iOS Charts library for the candlestick chart, I not able to find any way to draw custom views that is a triangle as shown in the image library.

I want to show the triangle(view) on the top and bottom of the candle based on the flag.

If this is not possible in Charts library please let me know the alternate library where I can achieve this.

CandleSitckChart

{

    chartView.delegate = self
    
    chartView.chartDescription?.enabled = true
    chartView.drawBordersEnabled = false
    chartView.drawGridBackgroundEnabled = false
    
    chartView.xAxis.labelTextColor = .white
    chartView.rightAxis.labelTextColor = .white
    
    chartView.dragEnabled = true
    chartView.setScaleEnabled(true)
    chartView.pinchZoomEnabled = true
    chartView.drawMarkers = true
    
    chartView.legend.enabled = false

    chartView.leftAxis.enabled = false
    
    chartView.leftAxis.spaceTop = 0.3
    chartView.leftAxis.spaceBottom = 0.3
    chartView.leftAxis.axisMinimum = 0
    chartView.rightAxis.enabled = true
    chartView.rightAxis.axisLineColor = .primaryBlue
    chartView.drawGridBackgroundEnabled = false
    
    let candleResponse = MasterData.shared.candleResponse
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "h:mm a"
    
    let dates = candleResponse
        .map { Date(timeIntervalSince1970: ($0.first ?? 0)/1000) }
        .map { dateFormatter.string(from: $0) }
    
    chartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: dates)
    chartView.xAxis.labelPosition = .bottom
    
    
    let yVals1 = (0..<candleResponse.count).map { (i) -> CandleChartDataEntry in
        return CandleChartDataEntry(x: Double(i),
                             shadowH: candleResponse[i][2],
                             shadowL: candleResponse[i][3],
                             open: candleResponse[i][1],
                             close: candleResponse[i][4])
    }
   
    let set1 = CandleChartDataSet(entries: yVals1)
    set1.setDrawHighlightIndicators(true)
    set1.drawVerticalHighlightIndicatorEnabled = true
    set1.drawHorizontalHighlightIndicatorEnabled = true

    set1.axisDependency = .right
    set1.setColor(UIColor(white: 80/255, alpha: 1))
    set1.drawIconsEnabled = true
    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 = true
    set1.neutralColor = .blue

    let data = CandleChartData(dataSet: set1)
    data.setDrawValues(false)
    chartView.data = data
}
0

There are 0 best solutions below