Search code examples
sparklines

How can I always show two decimal places with jQuery sparklines?


How can I show values with always two decimal numbers in sparkline tooltip? For example, I want 1.20 to show as "1.20" and not "1.2"?


Solution

  • found solution: sparkline has option: tooltipFormat, where you can format tooltip.

    var sparklineCharts = function(){
        $('#my_id').sparkline(currentMonthArray, sparklineSettings);
      };
    
    var sparklineSettings = {
        type: 'line',
        width: '100%',
        height: '50',
        lineColor: '#1ab394',
        fillColor: 'transparent',
        tooltipFormat: '{{y.2}}'
      };