0

I am using jqplot for showing graph.

following is the code :

tempArr1 = [9189.539999999999, 10170.039999999999, 980.5]

plot2 = $.jqplot('bar_chart_id1', [tempArr1], {
                            title:{
                                text: chatTitle2,
                                textColor: '#B66B09'
                            },
                            seriesDefaults:{
                                renderer:$.jqplot.BarRenderer,
                                rendererOptions: {
                                    // Set the varyBarColor option to true to use different colors for each bar.
                                    varyBarColor: true,
                                    barPadding: 2,
                                    barMargin: 3,
                                    barWidth: 30,
                                },
                                pointLabels: {show: true},  
                            },
                            axes: {
                                xaxis: {
                                    renderer: $.jqplot.CategoryAxisRenderer,
                                    ticks: lblArray,
                                    label:'Manufacturer',
                                },
                                yaxis:{
                                    labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                                    min: 0,
                                    tickInterval:1000,
                                    label:'Amount',
                                    tickOptions: {formatString: '$%#.2f'} 
                                }
                            },
                            highlighter: { show: true },
                        });

enter image description here As you can see the point label is showing many decimal points (9189.539999999999). I need to show the label as '$91890.54'. I have tried the formatString option in pointLabels as '$%#.2' buts its not working.

Any help is greatly appreciated. Thank you.

Shekhar Khairnar
  • 2,643
  • 3
  • 26
  • 44

3 Answers3

1
tempArr1 = [9189.539999999999, 10170.039999999999, 980.5];
tempArr1 = tempArr1.map(i => { return parseFloat(i.toFixed(2)); });
void
  • 36,090
  • 8
  • 62
  • 107
0

Round to at most 2 decimal places in JavaScript

Math.round(num * 100) / 100

Source

Community
  • 1
  • 1
ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58
0
 pointLabels: { show: true, location: 'n', lables: tempArr1 , formatString: "$%#.2f" },

Should meet your exact needs

twobob
  • 354
  • 8
  • 22