Skip to content

dynamic marker not visible on bar chart #5219

Open
@ashish-lava

Description

@ashish-lava

What did you do?

i am trying to make custom markers where i am using markerview and adding my custom dynamic views, but when i am clicking the bars it is highlighting but not showing my any markers at the top. nothing is visible. I have debugged it is going in refreshContent delegate but it is not showing any view.

What did you expect to happen?

i want my custom marker to be visible on click of bars

What happened instead?

bars are highlighted but it is not showing any markers

DGCharts Environment

DGCharts version/Branch/Commit Number: 5.1.0
Xcode version: 16
Swift version: 5
Platform(s) running DGCharts: ios
macOS version running Xcode:

Demo Project


class CommonMarker: MarkerView{
    
    private var customContentView: (UIView & MarkerUpdate)=MarkerUI(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
    private var markerFormat:MarkerFormat = .STEPS
    private var lineColor: UIColor?
    private let lineWidth: CGFloat = 2.0
    
    func setup(format:MarkerFormat,lineColor:UIColor = UIColor(red: 0.9, green: 0.2, blue: 0.2, alpha: 1.0)){
        self.lineColor = lineColor
        self.markerFormat = format
        self.customContentView.setupView(format: format)
        
        setupView()
    }
    
    private func setupView(){
        
        //customContentView.removeFromSuperview()
    
        //customContentView = view
        customContentView.translatesAutoresizingMaskIntoConstraints = false
        addSubview(customContentView)
        
        NSLayoutConstraint.activate([
            customContentView.topAnchor.constraint(equalTo: topAnchor),
            customContentView.leadingAnchor.constraint(equalTo: leadingAnchor),
            customContentView.trailingAnchor.constraint(equalTo: trailingAnchor),
            customContentView.bottomAnchor.constraint(equalTo: bottomAnchor)
        ])
        self.backgroundColor = .red
        
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
     
        customContentView.update(format: markerFormat, entry: entry, highlight: highlight)
        
        super.refreshContent(entry: entry, highlight: highlight)
        
    }
    
}


protocol MarkerUpdate{
    func update(format:MarkerFormat, entry: ChartDataEntry, highlight: Highlight)
    func setupView(format:MarkerFormat)
}

class MarkerUI: UIView{
    
    
    var unit:UILabel = UILabel()
    var value:UILabel = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
}

//constraints
extension MarkerUI{
    
    private func stepView(){
        unit.translatesAutoresizingMaskIntoConstraints = false
        value.translatesAutoresizingMaskIntoConstraints = false
        
        value.text = "1234"
        unit.text = "steps"
        
        let container = UIView()
        container.addSubview(value)
        container.addSubview(unit)
        
        NSLayoutConstraint.activate([
            unit.leadingAnchor.constraint(equalTo: container.leadingAnchor),
            unit.topAnchor.constraint(equalTo: container.topAnchor),
            value.leadingAnchor.constraint(equalTo: unit.trailingAnchor, constant: 5),
            value.trailingAnchor.constraint(equalTo: container.trailingAnchor)
        ])
        
        self.addSubview(container)
        
        NSLayoutConstraint.activate([
            container.centerYAnchor.constraint(equalTo: self.centerYAnchor),
            container.centerXAnchor.constraint(equalTo: self.centerXAnchor)
        ])
    }
}

//value updates
extension MarkerUI{
    
    private func updateStepView(value:Int){
        self.value.text = value.toString()
        self.unit.text = "steps"
    }
    
}

// update info
extension MarkerUI: MarkerUpdate{
    
    func update(format: MarkerFormat, entry: DGCharts.ChartDataEntry, highlight: DGCharts.Highlight) {
        switch format {
    }
    
}

i am setting marker to to bar chart as

 let marker = CommonMarker()
 marker.setup(format: .mark)
  marker.chartView = barChartView
        
 barChartView.marker = marker

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions