jQplot formatString“%n"; [英] jQplot formatString "%n"

查看:77
本文介绍了jQplot formatString“%n";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQplot有点问题.我正在尝试像这样做一个DateAxisRenderer: http://tinyurl.com/p8v5coh

我有这个: http://tinyurl.com/qd2lbxh

我不想轮换考试.我只想在小时和日期之间输入一个换行符.

有我的代码:

var plot1 = $.jqplot('chart1', [test2], {
        title:'Plot to test JQPLOT',
        legend: {
            show: true,
            placement: 'outsideGrid'
        }, 

    axesDefaults: {
        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
        tickOptions: {
            angle: 0,
            fontSize: '10pt'
        }
    },      


    axes: {
        xaxis: {
            label: "X Axis",
            renderer:$.jqplot.DateAxisRenderer, 
            tickOptions: {
                formatString: '%H %#.2f %n %#.2f %#d-%#m-%Y',
            },
            //min:'June 16, 2008 8:00AM', 
            tickInterval:'14400000',
        },
        yaxis: {
            label: "Y Axis",
            renderer: $.jqplot.LogAxisRenderer,  
            tickOptions: {
                angle: 0
            }
        }
    },
    highlighter: {
        show: true,
        sizeAdjust: 20,
    },
    cursor:{
        show: true,
        zoom: true,
        showTooltip:false
    },
    series:[{showMarker:false}],
});

如您所见,我已经尝试过'%n',因为它是在[官方文档] [1]中编写的. 我认为这是个白痴,但我自己无法解决这个问题.换行符不起作用.

您能告诉我正确的方法吗?

Ty

jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html

解决方案

jqplot有时会对轴和标签做一些奇怪的事情.这就是为什么我通常手动定义自己的坐标轴刻度:

axes: {
            xaxis: {
                tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                label: 'Date',
                tickOptions:{formatString:'%b %Y'},
                pad: 0,
                ticks: lsTicks,
                renderer: $.jqplot.DateAxisRenderer
            },

其中lsTicks看起来像这样:

["2014-01", "2014-02", "2014-03", "2014-04"]

,其长度与您的数据相同.为了使内容更具可读性,您可以添加tickOptions: {angle: -20},,以便在彼此相邻的日期过多的情况下以一定的角度显示日期.

tickOptions:{formatString:'%b %Y'}说:显示3个字母的月,然后显示4位数字的年.有关更多选项和信息,请参见此处.

或者,您可以使用minmaxtickInterval,但是我发现它们有时行为不当.请参见此处http://tinyurl.com/p8v5coh

And i've this : http://tinyurl.com/qd2lbxh

I don't want to make a rotation on my test. I just want to input a line break between my hour and my date.

There is my code :

var plot1 = $.jqplot('chart1', [test2], {
        title:'Plot to test JQPLOT',
        legend: {
            show: true,
            placement: 'outsideGrid'
        }, 

    axesDefaults: {
        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
        tickOptions: {
            angle: 0,
            fontSize: '10pt'
        }
    },      


    axes: {
        xaxis: {
            label: "X Axis",
            renderer:$.jqplot.DateAxisRenderer, 
            tickOptions: {
                formatString: '%H %#.2f %n %#.2f %#d-%#m-%Y',
            },
            //min:'June 16, 2008 8:00AM', 
            tickInterval:'14400000',
        },
        yaxis: {
            label: "Y Axis",
            renderer: $.jqplot.LogAxisRenderer,  
            tickOptions: {
                angle: 0
            }
        }
    },
    highlighter: {
        show: true,
        sizeAdjust: 20,
    },
    cursor:{
        show: true,
        zoom: true,
        showTooltip:false
    },
    series:[{showMarker:false}],
});

As you can see, i've tried '%n' as it's write in the [official doc][1]. I think it's idiot, but I can't solve this problem myself. The line break doesn't work.

Can you show me the right way?

Ty

jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html

解决方案

jqplot sometimes does strange things with axes and labels. That's why I usually manually define my own axes ticks like this:

axes: {
            xaxis: {
                tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                label: 'Date',
                tickOptions:{formatString:'%b %Y'},
                pad: 0,
                ticks: lsTicks,
                renderer: $.jqplot.DateAxisRenderer
            },

where lsTicks looks lomething like this:

["2014-01", "2014-02", "2014-03", "2014-04"]

and its length is the same as your data. To make things more readable, you can add tickOptions: {angle: -20},, so that your dates come in at an angle if you have too many to fit next to each other.

tickOptions:{formatString:'%b %Y'} says: display a 3 letter month, then a 4 digit year. For more options and info, see here.

Alternatively, you can use min, max and tickInterval, but I have found that they misbehave sometimes. See here and here for more.

这篇关于jQplot formatString“%n";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆