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 use callback function for tooltop.formatter? #9

Closed
vapao opened this issue Sep 27, 2016 · 5 comments
Closed

how to use callback function for tooltop.formatter? #9

vapao opened this issue Sep 27, 2016 · 5 comments
Labels

Comments

@vapao
Copy link

vapao commented Sep 27, 2016

At javascript:

tooltip: {
    formatter: function () {
        return new Date(this.x).toLocaleString() + '<br><b>内存:</b>' + byte_to_string(this.y)
    }
}

But typescript this is a class.

@cebor
Copy link
Owner

cebor commented Sep 27, 2016

The options object gets extracted from the Charts object, so it should work as you described.

new Chart({
...
tooltip: {
  formatter: function () {
     return new Date(this.x).toLocaleString() + '<br><b>内存:</b>' + byte_to_string(this.y)
  }
}
...
});

Docs: http://www.highcharts.com/docs/chart-concepts/tooltip

@vapao
Copy link
Author

vapao commented Sep 28, 2016

@cebor thanks
byte_to_string is a function convert Byte to KB MB or GB, like this:

private byteToString(data: any): string {
        let kb = data / 1024
        if (kb > 1024) {
            let mb = kb / 1024
            if (mb > 1024) {
                return (mb / 1024).toFixed(2) + ' GB'
            } else {
                return mb.toFixed(2) + ' MB'
            }
        }
        return kb.toFixed(2) + ' KB'
    }

now browser console print: Uncaught TypeError: this.byteToString is not a function

@cebor
Copy link
Owner

cebor commented Sep 28, 2016

I think the Problem is that, the options object and the class where you creating the Chart have different contexts.

Maybe making byteToString to a static method will solve this. - Example

Or use something like: var _this = this.

For further help, please show me more code of the class you declaring your chart.

@cebor cebor added the question label Sep 28, 2016
@cebor
Copy link
Owner

cebor commented Sep 30, 2016

I think, the problem is solved, so i'm closing this. Feel free to reopen.

@cebor cebor closed this as completed Sep 30, 2016
@vapao
Copy link
Author

vapao commented Oct 9, 2016

yes, is solved. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants