How to format numbers in Google API Linechart? -


i need format numbers in axis , numbers appear when hover mouse on line chart.

there 2 steps involved. first step find out pattern should use; second step put pattern in proper place in code. make post more beautiful, show step 2 , step 1.

step 2: putting pattern in code

here's code:

var options = {         haxis: {format:'###,###'}         vaxis: {title: 'time', format:'0.0e00'},     };     var formatter1 = new google.visualization.numberformat({pattern:'###,###'});     formatter1.format(datatable, 0);     var formatter2 = new google.visualization.numberformat({pattern:'0.0e00'});     formatter2.format(datatable, 1);     var fchartvar = new google.visualization.linechart(document.getelementbyid('fchart'));     fchartvar.draw(datatable, options); 

vaxis: {title: 'time', format:'0.0e00'} formats labels on vertical axis.

this formats numbers see when hover on points on line chart:

var formatter1 = new google.visualization.numberformat({pattern:'0.0e00'}); formatter1.format(datatable, 1); 

note how (datatable,0) formats haxis information while (datatable,1) formats vaxis information (again, see when hover on points on line chart).

the last 2 lines of code:

var fchartvar = new google.visualization.linechart(document.getelementbyid('fchart')); fchartvar.draw(datatable, options); 

are 2 compare own chart. replace fchartvar,datatable , fchart names used in code. if you're using other line chart, replace linechart chart you're using.

an example of 0.0e00 turning 1,234 1.2e03.

step 1: finding right pattern

google numberformat documentation

numberformat supports following options, passed in constructor: (source: google numberformat documentation)

decimalsymbol

  • a character use decimal marker. default dot (.).

fractiondigits

  • a number specifying how many digits display after decimal. default 2. if specify more digits number contains, display zeros smaller values. truncated values rounded (5 rounded up).

groupingsymbol

  • a character used group digits left of decimal sets of three. default comma (,).

negativecolor

  • the text color negative values. no default value. values can acceptable html color value, such "red" or "#ff0000".

negativeparens

  • a boolean, true indicates negative values should surrounded parentheses. default true.

pattern

  • a format string. when provided, other options ignored, except negativecolor.

    the format string subset of icu pattern set. instance, {pattern:'#,###%'} result in output values "1,000%", "750%", , "50%" values 10, 7.5, , 0.5.

prefix

  • a string prefix value, example "$".

suffix

  • a string suffix value, example "%".

icu decimalformat reference

as might have noticed google numberformat documentation above, can find out more detailed information formatting numbers icu decimalformat reference. here of important information icu decimalformat reference (it's in 'middle' of webpage):

enter image description here

a decimalformat pattern contains postive , negative subpattern, example, "#,##0.00;(#,##0.00)". each subpattern has prefix, numeric part, , suffix. if there no explicit negative subpattern, negative subpattern localized minus sign prefixed positive subpattern. is, "0.00" alone equivalent "0.00;-0.00". if there explicit negative subpattern, serves specify negative prefix , suffix; number of digits, minimal digits, , other characteristics ignored in negative subpattern. means "#,##0.0#;(#)" has precisely same result "#,##0.0#;(#,##0.0#)".

the prefixes, suffixes, , various symbols used infinity, digits, thousands separators, decimal separators, etc. may set arbitrary values, , appear during formatting. however, care must taken symbols , strings not conflict, or parsing unreliable. example, either positive , negative prefixes or suffixes must distinct parse() able distinguish positive negative values. example decimal separator , thousands separator should distinct characters, or parsing impossible.

the grouping separator character separates clusters of integer digits make large numbers more legible. commonly used thousands, in locales separates ten-thousands. grouping size number of digits between grouping separators, such 3 "100,000,000" or 4 "1 0000 0000". there 2 different grouping sizes: 1 used least significant integer digits, primary grouping size, , 1 used others, secondary grouping size. in locales these same, different. example, if primary grouping interval 3, , secondary 2, corresponds pattern "#,##,##0", , number 123456789 formatted "12,34,56,789". if pattern contains multiple grouping separators, interval between last 1 , end of integer defines primary grouping size, , interval between last 2 defines secondary grouping size. others ignored, "#,##,###,####" == "###,###,####" == "##,#,###,####".

illegal patterns, such "#.#.#" or "#.###,###", cause decimalformat set failing uerrorcode.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -