0

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
}
  • 1
    Hi Mehul - welcome to Stack. Post your code so we can take a look. – Johnny Rockex May 17 '21 at 17:24
  • Can you please look at the image? I want to know how to draw that kind of view. @JohnnyRockex – Mehul Makwana May 18 '21 at 06:31
  • You can't do it from this level - you'll need to drop down into lower code to adapt the draw function. What you're asking for isn't too complex though - you could draw your own instead of using a library. – Johnny Rockex May 19 '21 at 07:11
  • @JohnnyRockex can you please provide some kind of reference or guidance so that I can figure it out how to do that. – Mehul Makwana May 20 '21 at 08:34

0 Answers0