【问题标题】:jQPlot force static minimum and maximum values on y-axisjQPlot 强制 y 轴上的静态最小值和最大值
【发布时间】:2013-07-29 16:09:28
【问题描述】:

我正在使用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 } );

【问题讨论】:

    标签: jquery user-interface graph jqplot


    【解决方案1】:

    将此添加到您的axes:

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

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

    当您尝试重置轴时,请将这些设置添加到您的 replot 函数中:

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

    你可以说

    plot3.replot(false);
    

    所以它不会重置你的坐标轴。

    【讨论】:

    • 复制了您的代码($.jqplot({}); 内的所有代码。仍然无法正常工作。您使用的是什么版本?
    • 什么版本??你能为你的代码创建一个jsfiddle吗...让我看看你要做什么......
    • 它不适合你,因为在 replot 你正在重置你的轴...请在你的 replot 调用中指定我的代码。
    • 我会测试一下并告诉你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    相关资源
    最近更新 更多