格式化jqPlot点标签,如:number(percent)

时间:2022-01-27 18:53:33

this is my first question.

这是我的第一个问题。

I need to format a jqPlot chart point labels like this: 50 (100%) Formating number and show percentage.

我需要格式化一个jqPlot图表点标签,如下所示:50(100%)格式化数字和显示百分比。

var s1 = [32, 28, 18, 6];

var ticks = ['0-20 kph', '21-40 kph', '41-60 kph', '61+ kph'];

plot1 = $.jqplot('bar-graph', [s1], {
    animate: !$.jqplot.use_excanvas,
    title: 'Gráficos de velocidade',
    captureRightClick: true,
    seriesColors: ['green', 'yellow', 'orange', 'red'],
    seriesDefaults: {
        renderer: $.jqplot.BarRenderer,
        pointLabels: {
            show: true,
            formatString: '%s (?%%)' 
        },
        rendererOptions: {
            varyBarColor: true
        }
    },
    axes: {
        xaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            ticks: ticks
        }
    },
    highlighter: {
        show: false
    }
});

On jsFinddle: http://jsfiddle.net/evandroprogram/r3PUE/10/

在jsFinddle上:http://jsfiddle.net/evandroprogram/r3PUE/10/

Thanks.

1 个解决方案

#1


8  

You can probably implement a function which returns a proper format string instead of setting the format explicitly. Something like this:

您可以实现一个返回正确格式字符串的函数,而不是显式设置格式。像这样的东西:

formatString: function(){return '%s (100%)';}()

You can do your calculations inside that function to come up with the appropriate string.

您可以在该函数内进行计算,以获得适当的字符串。

#1


8  

You can probably implement a function which returns a proper format string instead of setting the format explicitly. Something like this:

您可以实现一个返回正确格式字符串的函数,而不是显式设置格式。像这样的东西:

formatString: function(){return '%s (100%)';}()

You can do your calculations inside that function to come up with the appropriate string.

您可以在该函数内进行计算,以获得适当的字符串。