首页 文章

jqPlot日期轴 - 在错误的日子绘制的条形图?

提问于
浏览
2

这里很简单的东西:

var dataHits = [['2011-10-16',1],['2011-11-05',7],['2011-11-06',1],['2011-11-09',2],['2011-11-12',5]];
   var plot1 = $.jqplot('chartHits', [dataHits], {
      title:'Zobrazenia profilu spolu',
      seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                rendererOptions: {            
            barPadding: 0,      // number of pixels between adjacent bars in the same
                                // group (same category or bin).
            barMargin: 0,      // number of pixels between adjacent groups of bars.
            barDirection: 'vertical', // vertical or horizontal.
            barWidth: 10

        }                
            },
      axes:{
        xaxis:{                    
          renderer:$.jqplot.DateAxisRenderer,
          min: '2011-10-15',
          max: '2011-11-13',
          tickInterval: "2 day",
          tickOptions:{
            formatString:'%d.%m'
          }          
        },
        yaxis:
        {
          min: 0,
          tickInterval: 1
        }        
      },
      highlighter: {
        show: true,
        sizeAdjust: 7.5
      },
      cursor: {
        show: false
      }
   });

但生成的图形是错误的 - 第一个值被绘制好 - 在2011年10月16日,但所有其他值(条形图)定位不正确 - 比它们应该早一天(甚至它们的“工具提示”,当突出显示是好的,它们只是在x轴上的错误位置) . 知道如何解决这个问题吗?

见图:
enter image description here

1 回答

  • 1

    我认为一般来说,在处理条形图时,你应该总是使用刻度线来获得更好的情节 . 同样针对您的问题,您在使用_2719073时获得了有趣的结果 . 在这里您需要记住,如果您想要在 dataHits 中未指定的日期显示任何内容,您需要提供它们以及仅给它们值0 .

    当您同时使用 ticksdateAxisRenderer 功能时,您获得了有趣的结果( hope this is what you want ) . This I show in the following sample.这里保留了显示读数之间时间距离的间隙,并正确绘制了所有值 . 同样重要的是要注意 minmaxtickInterval 没有任何影响,因为我们使用刻度线 .

    BTW: 如果您仍想在图表周围留下一些空白,可以申请the approach presented in EDIT of this answer .

相关问题