jQPlot强制y轴上的静态最小值和最大值
我正在使用jqPlot来渲染条形图,我希望做一些相当简单的事情,但我不确定图书馆是否有这个选项。
我有这样的图形,其中y轴上的最大可能值可以是42。
假设对于一个案例,我对任何一个柱的最高值是14,那么图形将呈现为最多只显示14个。
但是,我想要这样,在所有情况下,我可以看到42的上限呈现。
这就是我现在所拥有的:
var plot3 = $.jqplot('chart3', [line1], { animate: true, animateReplot: true, seriesDefaults: {renderer: $.jqplot.BarRenderer}, series:[{ pointLabels:{ show: true, labels:[depression, anxiety, stress] }, rendererOptions: { animation: { speed: 3500 }, barWidth: 50, barPadding: -15, barMargin: 0, varyBarColor : true, highlightMouseOver: false } }], axes: { xaxis: { renderer:$.jqplot.CategoryAxisRenderer } }, canvasOverlay: { show: true, objects: [{ horizontalLine: { y: 42, lineWidth: 3, color: 'rgb(255,0,0)', shadow: true, xOffset: 0 } }] } }); plot3.replot( { resetAxes: true } );
将此添加到您的axes:
axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer }, yaxis: { min:0, max:42 } },
您可以添加tickInterval
来指定tickInterval
的刻度之间的间隔
当您尝试重置轴时,请将这些设置添加到您的replot
function:
plot3.replot({axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer }, yaxis: { min:0, max:42 } }});
要么
你可以说
plot3.replot(false);
所以它不会重置您的轴。