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 do you override the getFormattedValue() method when it doesn't exist? #3506

Closed
JCMcLovin opened this issue Jun 12, 2018 · 2 comments
Closed

Comments

@JCMcLovin
Copy link
Contributor

The documentation markup in ValueFormatter says, 'override the getFormattedValue(...) method' but there's no such method in the library.

Is this a bug and it's missing or is the documentation wrong?

import Foundation

/// Interface that allows custom formatting of all values inside the chart before they are being drawn to the screen.
///
/// Simply create your own formatting class and let it implement ValueFormatter.
///
/// Then override the getFormattedValue(...) method and return whatever you want.

@objc(ChartValueFormatter)
public protocol ValueFormatter: class
{
    
    /// Called when a value (from labels inside the chart) is formatted before being drawn.
    ///
    /// For performance reasons, avoid excessive calculations and memory allocations inside this method.
    ///
    /// - returns: The formatted label ready for being drawn
    ///
    /// - parameter value:           The value to be formatted
    ///
    /// - parameter axis:            The entry the value belongs to - in e.g. BarChart, this is of class BarEntry
    ///
    /// - parameter dataSetIndex:    The index of the DataSet the entry in focus belongs to
    ///
    /// - parameter viewPortHandler: provides information about the current chart state (scale, translation, ...)
    ///
    func stringForValue(_ value: Double,
                        entry: ChartDataEntry,
                        dataSetIndex: Int,
                        viewPortHandler: ViewPortHandler?) -> String
}
@liuxuan30
Copy link
Member

can you just check out the demos? if the comment is wrong, you could file a PR to fix it.

@JCMcLovin
Copy link
Contributor Author

Yes, I'll file a PR. I wanted to make sure I wasn't missing something before making any changes.

There are so many questions about formatting axis labels as something other than an index value it would be very helpful if the documentation described how to do it and gave examples. Yes, I know some of the demos do it but there's a lot going on to render the axes and their labels so it difficult to understand what it's actually doing. I've stepped through the code countless times and still not sure how it really does it. Less experienced developers like myself would really benefit from this.

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