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

Allowing date formatting for google chart tooltips via google.visualization.DateFormat #10

Closed
alterx opened this issue Oct 21, 2013 · 4 comments

Comments

@alterx
Copy link

alterx commented Oct 21, 2013

We're using chartkick for a project and we've come into the need of formatting the dates inside the tooltips.

Achieving this is as easy as adding a couple of lines to the following function using the formatter provided by google.

renderLineChart = function (element, series, opts) {
      waitForLoaded(function () {
        var options = jsOptions(series, opts);
        var data = createDataTable(series, "datetime");
        var formatter = new google.visualization.DateFormat({ 
             pattern: options.pattern 
        }); 
        formatter.format(data, 0);
        var chart = new google.visualization.LineChart(element);
        resize(function () {
          chart.draw(data, options);
        });
      });
    };

In general you could add the option to send the formatter as a parameter and apply it in the required functions.

@ankane
Copy link
Owner

ankane commented Oct 21, 2013

Great, this solution looks nice and clean. I'm a bit torn at the moment - worried about breaking compatibility w/ Highcharts yet don't want to keep useful features out.

@alterx
Copy link
Author

alterx commented Oct 21, 2013

I think there's also an option to format the tooltips in Highcharts (http://api.highcharts.com/highcharts#Highcharts.dateFormat()).

I'll put something together and submit a pull request

@tagliala
Copy link

@ankane thanks for pointing me out this pull request

@alterx thanks I was looking for this one.

There is another thing that IMHO could be interesting in tooltips: format the "number" in the tooltip. Unfortunately I don't have time to dig into this library, so my workaround is an ugly rows[key][i] = toFloat(d[1].toFixed(2));

Refers to ankane/chartkick#46

@ankane
Copy link
Owner

ankane commented Feb 23, 2018

Cleaning up old issues

@ankane ankane closed this as completed Feb 23, 2018
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