Javascript JQplot barRenderer “y 轴”值从负值开始
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6204496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQplot barRenderer "y-axis" values start from negative values
提问by soniaP
Does anyone know how to make "y-axis" values start from 0 in Jqplot....by default it starts with negative values for eg: -500, 0, 500, 1000 and so on....Please help
有谁知道如何在 Jqplot 中使“y 轴”值从 0 开始......默认情况下它以负值开头,例如:-500、0、500、1000 等等......请帮忙
回答by Nerds of Technology
Set min: object (minimum) to 0 within axes: object
在轴内将 min: object (minimum) 设置为 0: object
$(document).ready(function(){
// your code here... //
axes:{
yaxis: {min:0}
}
})
As rsapru suggested, a max: object (maximum) value is recommended to bound the graph to your preferred range. For example, if you wanted the minimum to be 0 and maximum to be 7500
正如 rsapru 建议的那样,建议使用 max: object (maximum) 值将图形绑定到您的首选范围。例如,如果您希望最小值为 0,最大值为 7500
axes:{
yaxis: {min:0, max: 7500}
}
If you want to specify the graduations of the ticks you can do so manually by specifying ticks with the ticks: object or have jqPlot calculate tick spacing automatically (nothing other than min and max objects would be needed in that case) or by your specific number of ticks (using numberTicks: object)
如果您想指定刻度的刻度,您可以通过使用刻度指定刻度来手动完成:对象或让 jqPlot 自动计算刻度间距(在这种情况下,除了最小和最大对象之外不需要其他任何对象)或通过您的特定数字滴答数(使用 numberTicks: 对象)
Example: For tick 100 units apart, from 0 to 1000, using 11 ticks (0,100,200,300,400,500,600,700,800,900,1000) jqPlot automatic calculation:
示例:对于间隔 100 个单位的刻度,从 0 到 1000,使用 11 个刻度 (0,100,200,300,400,500,600,700,800,900,1000) jqPlot 自动计算:
axes:{
yaxis: {min:0, max: 1000, numberTicks: 11}
}
Example: For tick 100 units apart, from 0 to 1000, using 11 ticks (0,100,200,300,400,500,600,700,800,900,1000) manual specification:
示例:对于间隔 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]]}
}
回答by PackedUp
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 will star the Y axis to start from 0.
pad: 0 将使 Y 轴从 0 开始。
回答by rsapru
Refer to http://www.jqplot.com/docs/files/jqPlotOptions-txt.html
参考http://www.jqplot.com/docs/files/jqPlotOptions-txt.html
set yaxis: {min: 0, max: 500, numberTicks:5}
设置 yaxis: {min: 0, max: 500, numberTicks:5}
回答by john
add yaxis: {min:0} in your yaxis
在您的 yaxis 中添加 yaxis: {min:0}
回答by Alekhya
Add the following to the script:
将以下内容添加到脚本中:
yaxis: {
minimum:0
}
in your yaxis. I tried it and it works.
在你的 yaxis 中。我试过了,它有效。
回答by Muhammad Adnan
The following solution work for me.
以下解决方案对我有用。
-> Add zero value in array also.
-> 也在数组中添加零值。
-> set the data render to $.jqplot.CanvasAxisLabelRenderer
-> 将数据渲染设置为 $.jqplot.CanvasAxisLabelRenderer
yaxis: { renderer: $.jqplot.CanvasAxisLabelRenderer .....
yaxis: { 渲染器: $.jqplot.CanvasAxisLabelRenderer .....
}
Thanks Adnan
谢谢阿德南