The formatter only adds formatting to the data table column.  It does not
return a column to be used by a calc function.

A column with the annotation role uses the *value* as a string in the
annotation display.  It would make sense to extend this to also look for a
formatted representation and use that instead.

So what you want is to specify a calc function that returns the
getFormattedValue() of column one for the same row.  The calc function
takes a datatable and a row as input and a value is expected as output.

calc: function(dt, row) { return data.getFormattedValue(row, 1); }

See
https://developers.google.com/chart/interactive/docs/reference#DataTable_getFormattedValue

On Fri, Jun 15, 2018 at 12:33 PM Jeff Poslinski <[email protected]> wrote:

> Hi all,
>
> I'm trying to format the value in the bar chart, so far it works only for
> the tooltips but not the ones displayed in the bar:
>
>
> <https://lh3.googleusercontent.com/-D4BAd-TJwr8/WyPpcKVkXhI/AAAAAAAAEUo/lCM9iJKdATcCT8X30ngT8m47-YEkEqiRgCLcBGAs/s1600/screenshot.png>
> Below is my snippet:
>
> var data = google.visualization.arrayToDataTable([
>         ['Item', 'Percentage', {role: 'style'}],
>         ['Item 1', 0.6721, 'color:#00CCFF'],
>         ['Item 2', 0.2295, 'color:#00CCFF'],
>         ['Item 3', 0.0984, 'color:#00CCFF']
>       ]);
>
>       var formatter = new google.visualization.NumberFormat({pattern:
> '0.00%'});
>
>       var view = new google.visualization.DataView(data);
>       view.setColumns([0, 1,
>                        { calc: formatter.format(data, 1),
>                          sourceColumn: 1,
>                          type: "number",
>                          role: "annotation" },
>                        2]);
>
> Any help would be greatly appreciated.
>
> Regards,
> Jeff
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to
> [email protected].
> Visit this group at
> https://groups.google.com/group/google-visualization-api.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-visualization-api/ea794373-f975-4e1b-a577-c4e92eb678dc%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/ea794373-f975-4e1b-a577-c4e92eb678dc%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>
[email protected] <[email protected]>   5CC, Cambridge MA

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJP3-mw2PMObYBz0uegQzhmedKkY%2BzQeHPswkHDVN%2B5kSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to