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

How to create a custom marker view in line chart for showing x values as well #2562

Closed
samarth220194 opened this issue Jun 27, 2017 · 8 comments

Comments

@samarth220194
Copy link

I want to show the x values in the line chart as well, how do i create a markerview for that

@thierryH91200
Copy link
Contributor

try

import Foundation
import Charts

open class XYMarkerView1: BalloonMarker
{
    open var xAxisValueFormatter: IAxisValueFormatter?
    open var yAxisValueFormatter: IAxisValueFormatter?
    fileprivate var yFormatter = NumberFormatter()
    
    public init(color: NSColor, font: NSFont, textColor: NSColor, insets: EdgeInsets, xAxisValueFormatter: IAxisValueFormatter, yAxisValueFormatter : IAxisValueFormatter)
    {
        super.init(color: color, font: font, textColor: textColor, insets: insets)
        self.xAxisValueFormatter = xAxisValueFormatter
        self.yAxisValueFormatter = yAxisValueFormatter
         yFormatter.minimumFractionDigits = 1
        yFormatter.maximumFractionDigits = 1
    }
    
    open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
    {
        let x = entry.x
        let y = entry.y
        
        setLabel("x: " + xAxisValueFormatter!.stringForValue(x, axis: nil) + ", y: " + yAxisValueFormatter!.stringForValue(y, axis: nil))
    }
}

@samarth220194
Copy link
Author

samarth220194 commented Jun 27, 2017

When I am calling the function refreshContent(entry: ChartDataEntry, highlight: Highlight ) then it is showing the error: "Extra argument highlight in call"

@thierryH91200
Copy link
Contributor

@samarth220194
Copy link
Author

samarth220194 commented Jun 27, 2017

Sir see this, i called the function like this :
It gave me error : extra argument 'highlight' in call

`
let c_marker = XYMarkerView1(color: UIColor.white, font: UIFont(name: "Helvetica", size: 10)!,
textColor: UIColor.black, insets: UIEdgeInsets(top: 2.0, left: 3.0, bottom: 2.0, right: 3.0),
xAxisValueFormatter: <#IAxisValueFormatter#>)

        c_marker.refreshContent(entry: DataEntry, highlight: Highlight (x : Double(i) , y : Values[i] , dataSetIndex : i))
        {
            let x = DataEntry.x
            let y = DataEntry.y
               setLabel("x: " + xAxisValueFormatter!.stringForValue(x, axis: nil) + ", y: " + yAxisValueFormatter!.stringForValue(y, axis: nil))
        }

`

@thierryH91200
Copy link
Contributor

   The correct syntax is:
 let  marker = XYMarkerView( color:  NSUIColor.yellow, 
                                   font: NSUIFont.systemFont(ofSize: 12.0),
                                    textColor: NSUIColor.blue,
                                    insets: UIEdgeInsets(top: 2.0, left: 3.0, bottom: 2.0, right: 3.0),
                                    xAxisValueFormatter: yourFormatter,
                                    yAxisValueFormatter: yourFormatter)
        marker.minimumSize = CGSize( width: 80.0, height :40.0)
        marker.chartView = chartView
        chartView.marker = marker

it's all

@samarth220194
Copy link
Author

Okk i got it , but why didnt we used the function refresh content ?

@thierryH91200
Copy link
Contributor

it's automatic

@samarth220194
Copy link
Author

Okk thank you Sir for the help :)

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