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 show custom text on Y-axis of Line Chart? #1720

Closed
rameswarprasad opened this issue Oct 26, 2016 · 3 comments
Closed

How to show custom text on Y-axis of Line Chart? #1720

rameswarprasad opened this issue Oct 26, 2016 · 3 comments

Comments

@rameswarprasad
Copy link

I'm using line chart view in my app. Here's the screenshot of the line chart.
line chart

However I don't want the auto-calculated values on the y-axis (e.g 1.800, 2.000, 2.200), instead I want to put my unit value, e.g 'miles/h', 'meters/sec' etc.

How can I achieve this?

I also want to toggle values on a node when tapped. Is there a way to achieve this?

I've searched for the first one I didn't find it.

@thierryH91200
Copy link
Contributor

thierryH91200 commented Oct 26, 2016

It's not complicated

let leftAxis = scatterChartView.leftAxis
leftAxis.valueFormatter = DoubleAxisValueFormatter(postFixe: "m/s")

and

open class DoubleAxisValueFormatter : NSObject, IAxisValueFormatter
{
    open var postFixe :String = ""
    public init(postFixe: String)
    {
        self.postFixe = postFixe
    }
    public func stringForValue(_ value: Double, axis: AxisBase?) -> String
    {
        let formatter = NumberFormatter()
        formatter.minimumFractionDigits = 2
        formatter.maximumFractionDigits = 2
        formatter.localizesFormat = true
        let num = NSDecimalNumber(value: value)
        let strVal = formatter.string( from: num)
        let str = strVal! + " " + postFixe
        return str
    }
}

@liuxuan30
Copy link
Member

edited @thierryH91200 post. good job!

@rameswarprasad
Copy link
Author

rameswarprasad commented Nov 2, 2016

Guys thanks for helping out, however I'm using version 2.2.5. Can you help out as I believe the above answer is valid only for 3.0 and above of charts version.

And also it's just I want to display 'visits/day', no number. Left axis just has a textual unit representation.

Thanks in advance.

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