JQplot的barRenderer中,“y轴”数值从负值开始。

7

有人知道如何使Jqplot中的“y轴”值从0开始吗?默认情况下,它从负值开始,例如:-500、0、500、1000等等...请帮忙解决。

6个回答

19

将对象(最小值)在对象中的轴设置为0。

$(document).ready(function(){
 // your code here... //
 axes:{
  yaxis: {min:0}
 }
})

如rsapru建议的那样,推荐使用max:对象(最大值)来限制图表到您想要的范围。例如,如果您希望最小值为0,最大值为7500。

 axes:{
  yaxis: {min:0, max: 7500}
 }
如果你想要指定刻度的间隔,你可以手动使用ticks对象指定刻度,或者让jqPlot自动计算刻度间距(在这种情况下,除了最小值和最大值对象,不需要其他任何对象),又或者使用numberTicks对象来指定特定数量的刻度。
例如:如果要设置从0到1000,间隔100个单位的11个刻度(0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000),可以使用jqPlot的自动计算功能。
 axes:{
  yaxis: {min:0, max: 1000, numberTicks: 11}
 }

示例:对于间隔为100个单位的刻度,从0到1000,使用11个刻度(0、100、200、300、400、500、600、700、800、900、1000)手动指定:

 axes:{
  yaxis: {min:0, max: 1000, Ticks: [[0],[100],[200],[300],[400],[500],[600],[700],[800],[900],[1000]]}
 }

你能告诉我如何计算没有明确设置的刻度数吗?我的意思是如果图表是正常创建的,那么我们是否可以获取图表中显示的刻度数。 - Hussain Akhtar Wahid 'Ghouri'
你可能需要将Nerds of Technology的答案与PackedUp的答案结合起来,以实现零y轴的效果,代码如下:axes : { yaxis: {min:0, pad: 0}} - Tim Cull

8
                var plot2 = $.jqplot ('chartdiv', getRequestStats(), {
                // Give the plot a title.
                title: 'Daily Request Status',
                // You can specify options for all axes on the plot at once with
                // the axesDefaults object.  Here, we're using a canvas renderer
                // to draw the axis label which allows rotated text.
                axesDefaults: {
                    labelRenderer: $.jqplot.CanvasAxisLabelRenderer
                },
                // An axes object holds options for all axes.
                // Allowable axes are xaxis, x2axis, yaxis, y2axis, y3axis, ...
                // Up to 9 y axes are supported.
                axes: {
                    // options for each axis are specified in seperate option objects.
                    xaxis: {
                        label: "Hour",
                        // Turn off "padding".  This will allow data point to lie on the
                        // edges of the grid.  Default padding is 1.2 and will keep all
                        // points inside the bounds of the grid.
                        pad: 0
                    },
                    yaxis: {
                        label: "Count",
                        pad: 0
                    }
                }
            });

pad:0会使Y轴从0开始。


我在y轴上已经设置了min:0,但它不起作用。添加了pad:0就可以了。 - Kiran

3

1
在你的 y 轴中添加 yaxis: {min:0}。

0
以下解决方案对我有效。
-> 在数组中添加零值。
-> 将数据渲染设置为$.jqplot.CanvasAxisLabelRenderer yaxis: { renderer: $.jqplot.CanvasAxisLabelRenderer .....

                    }

谢谢 Adnan


0
将以下内容添加到脚本中:
yaxis: {
    minimum:0
}

在你的y轴上。我试过了,它有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接