jQPlot强制y轴上的静态最小值和最大值

kar*_*can 8 jquery user-interface graph jqplot

我正在使用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 } );
Run Code Online (Sandbox Code Playgroud)

Gya*_*eep 23

将此添加到您的 axes:

       axes: {
            xaxis: {           
                renderer: $.jqplot.CategoryAxisRenderer                   
            },
            yaxis: {
                min:0,
                max:42
            }
        },
Run Code Online (Sandbox Code Playgroud)

您可以添加tickInterval以指定刻度之间的间隔yaxis

replot在尝试重置轴时,请将这些设置添加到您的功能中:

     plot3.replot({axes: {
                xaxis: {           
                    renderer: $.jqplot.CategoryAxisRenderer                       
                },
                yaxis: {
                    min:0,
                    max:42
                }
            }});
Run Code Online (Sandbox Code Playgroud)

要么

你可以说

plot3.replot(false);
Run Code Online (Sandbox Code Playgroud)

所以它不会重置您的轴.

  • 它不适合你,因为在`replot`你重置你的轴...请在你的重新调用调用中指定我的代码. (3认同)