jQPlot icon indicating copy to clipboard operation
jQPlot copied to clipboard

AxisTickRenderer doesn't apply formatString to string values

Open Weblib opened this issue 10 years ago • 1 comments

The defaultTickFormatter in jqplot.axisTickRenderer applies the sprintf with the formatString only for number values.

jqplot.axisTickRenderer, line 164 :

    $.jqplot.DefaultTickFormatter = function (format, val) {
        if (typeof val == 'number') {
            if (!format) {
                format = $.jqplot.config.defaultTickFormatString;
            }
            return $.jqplot.sprintf(format, val);
        }
        else {
            return String(val);
        }
    };

This makes impossible to format string values. Example : I have a bar chart with 10 categories, the names are quite long and I want to print only the first few characters on the tick and let the full name in the highlighter. When i use a formatString such as "%.10s", it is completely ignored (any formatString really, the value being a string).

I think this behaviour was chosen because the default formatString for the categoryAxisRenderer is "%d" and weirds out strings (I guess)

Do you have any suggestion on how to fix/improve this behaviour ?

Felix from Weblib

Weblib avatar Sep 30 '14 15:09 Weblib

Formater for category is useless because the formatter let user transform numerical datas to String datas. In categoryAxisRenderer case the user can use String category dirrectly in datas.

It seems to be the reason why the formatter is only applied on Numerical datas.

svandecappelle avatar Oct 07 '14 07:10 svandecappelle