jQPlot force static minimum and maximum values on y-axis

一曲冷凌霜 提交于 2019-12-07 01:07:34

问题


I am using jqPlot to render bar charts and am looking to do something fairly straightforward but I am not sure if the library has an option for this.

I have graphs like this one, where the maximum possible value on the y-axis can be 42.

Let's say if for one case, my highest value for any of the bars is 14, then the graph will be rendered to show only up to 14.

However, I want it so that, IN ALL CASES, I can see that upper threshold of 42 rendered.

This is what I have for now:

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 } );

回答1:


Add this to your axes:

       axes: {
            xaxis: {           
                renderer: $.jqplot.CategoryAxisRenderer                   
            },
            yaxis: {
                min:0,
                max:42
            }
        },

you can add tickInterval to specify the interval between the ticks on yaxis

Please add these setting to your replot function as you are trying to reset the axis:

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

OR

You can say

plot3.replot(false);

so it will not reset your axes.



来源:https://stackoverflow.com/questions/17928868/jqplot-force-static-minimum-and-maximum-values-on-y-axis

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