jqPlot - time values on Y axis

[亡魂溺海] 提交于 2019-12-11 19:29:09

问题


I need to create graph with dates on X axis and times on Y axis.

My JS code is:

jQuery(document).ready(function ($) {
   var data = [["2013-04-25","00:11.557"],["2013-04-25","00:15.569"],["2013-04-25","00:11.733"],["2013-04-25","00:13.023"],["2014-04-26","00:22.333"]];
   var plot1 = $.jqplot('chartdiv', [data], {
     title:'Default Date Axis',
     axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}},
     series:[{lineWidth:4, markerOptions:{style:'square'}}]
     });
 });

The dates are showing correctly on the X axis, but I don't know how to display the values on Y axis.

How is this done in jqPlot plugin?


回答1:


I figured out the issue here.

The main issue here is y-axis take only numeric values like 11.557, 15.569, ... and so on.

Also, I need to add extra attribute tickOptions for x-axis as:

tickOptions:{formatString:'%Y-%m-%d'}

Here is what I got to work:

jQuery(document).ready(function($){ 
  var data = [["2013-04-25",11.557],["2013-04-25",15.569],["2013-04-25",11.733],["2013-04-25",13.023],["2013-04-26",22.333]];
  var plot1 = $.jqplot('chartdiv', [data], {
    title: 'Default Date Axis',
    axes:{
      xaxis: { 
        renderer: $.jqplot.DateAxisRenderer,
        tickOptions:{formatString:'%Y-%m-%d'}       
      }
    },
    series: [{ lineWidth: 4, markerOptions: { style:'square' }}]
  });
});

Working DEMO Link



来源:https://stackoverflow.com/questions/23311003/jqplot-time-values-on-y-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!