最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery jqPlot library 12 hour Time Y-Axis Inversion issue - Stack Overflow

programmeradmin1浏览0评论

I've started using jqPlot recently. The generated graphs look amazing and I love it. There are a few little things to learn here and there, but overall it's great.

I'm using the stacked bar generation and came into a werid issue. Basically, I want a 12 hour time from hours 0 - 24 on the Y axis, days on the X axis, and plot seconds of a certain activity on the graph. But also, I want the days (midnight) to start at the top of the graph, and e to the bottom.

I can flip the data easily with an inverse of the 'min' and 'max', but the issue arises when I try to flip the ticks; essentially, the "time".

I have my series defaults set to a hidden axis:

seriesDefaults: {
    renderer: $.jqplot.BarRenderer,
    yaxis: 'y2axis'
},

And I put a placeholder series ( with the values all 0's, eg: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ) to associate with a separate yaxis to plot the date ticks:

series: [
    { show: true, yaxis: 'yaxis', }
],

I can flip the values by changing the min and max on the default y axis and hiding it:

y2axis:{
    min: 24,
    max: 0,
    showTicks: false
}

Then I set the ticks, and format them with the DateAxisRenderer:

yaxis:{
    renderer:$.jqplot.DateAxisRenderer,
    ticks: ['0', '2', '4', '6', '8', '10', '12', '14', '16', '18', '20', '22', '24'],
    tickOptions: { formatString: '%I:%M %p' }
}

This creates a yaxis with the time's from 12:00 AM to 12:00PM back to 12:00 AM in that format. but in increasing order from the bottom of the graph.

Obviously, flipping the min and max on the 'yaxis' would acplish nothing, as there is only place holder values, and it only flips the values. How would I go about to flip the axis values so that the time goes (from the bottom) 24, 22, 20... etc, etc, ?

Thanks for your help in advance.

I've started using jqPlot recently. The generated graphs look amazing and I love it. There are a few little things to learn here and there, but overall it's great.

I'm using the stacked bar generation and came into a werid issue. Basically, I want a 12 hour time from hours 0 - 24 on the Y axis, days on the X axis, and plot seconds of a certain activity on the graph. But also, I want the days (midnight) to start at the top of the graph, and e to the bottom.

I can flip the data easily with an inverse of the 'min' and 'max', but the issue arises when I try to flip the ticks; essentially, the "time".

I have my series defaults set to a hidden axis:

seriesDefaults: {
    renderer: $.jqplot.BarRenderer,
    yaxis: 'y2axis'
},

And I put a placeholder series ( with the values all 0's, eg: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ) to associate with a separate yaxis to plot the date ticks:

series: [
    { show: true, yaxis: 'yaxis', }
],

I can flip the values by changing the min and max on the default y axis and hiding it:

y2axis:{
    min: 24,
    max: 0,
    showTicks: false
}

Then I set the ticks, and format them with the DateAxisRenderer:

yaxis:{
    renderer:$.jqplot.DateAxisRenderer,
    ticks: ['0', '2', '4', '6', '8', '10', '12', '14', '16', '18', '20', '22', '24'],
    tickOptions: { formatString: '%I:%M %p' }
}

This creates a yaxis with the time's from 12:00 AM to 12:00PM back to 12:00 AM in that format. but in increasing order from the bottom of the graph.

Obviously, flipping the min and max on the 'yaxis' would acplish nothing, as there is only place holder values, and it only flips the values. How would I go about to flip the axis values so that the time goes (from the bottom) 24, 22, 20... etc, etc, ?

Thanks for your help in advance.

Share Improve this question edited Jun 20, 2011 at 16:35 Bo Li asked Jun 20, 2011 at 16:26 Bo LiBo Li 1413 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6
  1. Replace:

    ticks: ['0', '2', '4', '6', '8', '10', '12', '14', '16', '18', '20', '22', '24']
    

    With:

    ticks: ['24', '22', '20', '18', '16', '14', '12', '10', '8', '6', '4', '2', '0']
    
  2. Replace:

    y2axis:{
        min: 24,
        max: 0,
        showTicks: false
    }
    

    With:

    y2axis:{
        min: 0,
        max: 24,
        showTicks: false
    }
    

This will sort the y axis normally but use a reverse tick sequence.

发布评论

评论列表(0)

  1. 暂无评论