Y 值为负时的 X 轴位置问题
Problem with X-axis position when Y values are negative
当我的 Y 值为负时,我无法在散点图底部显示 X 轴。 X 轴一直显示在 canvas 的顶部边缘(同时 X 标签正确定位)。
下面使用的 JS 代码,canvas 周围的 div 具有黑色背景,这就是轴和标签为白色的原因。谁能告诉我我错过了什么吗? (我是 RGraph 的新手,这是我的第一次试用)。
谢谢哔叽
// random 100 data points, x in 100..200, y in -120..-50
var data = [];
for(let i = 0; i < 100; i++) data.push([100+i, -50 - Math.random() * 70]);
var xmin = data[0][0], xmax = data[data.length - 1][0], ymin = data[0][1], ymax = data[0][1];
for(let i = 1; i < data.length; i++) { if(data[i][1] < ymin) ymin = data[i][1]; if(data[i][1] > ymax) ymax = data[i][1]; }
// scatter graph with white text, green lines, no ticks
var chart = new RGraph.Scatter({
id: 'chart',
data: data,
options: { backgroundGridDotted: true, marginLeft: 60, marginBottom: 50, line: true, tickmarksStyle: null, textColor: 'white',
xaxisScale: true, xaxisScaleMin: xmin, xaxisScaleMax:xmax, xaxisColor: 'white', xaxisTitle: 'Frequency (MHz)',
yaxisScaleMin: ymin, yaxisScaleMax: ymax, yaxisColor: 'white', yaxisTitle: 'Received Power Level (dBm)'
}
}).draw();
试试这个:
https://codepen.io/rgraph/full/QWKbRwr
(使用“更改视图”按钮查看代码)
<script src="https://www.rgraph.net/libraries/RGraph.common.core.js"></script>
<script src="https://www.rgraph.net/libraries/RGraph.drawing.xaxis.js"></script>
<script src="https://www.rgraph.net/libraries/RGraph.scatter.js"></script>
<div style="display: inline-block; background-color: black">
<canvas id="cvs" width="600" height="250"></canvas>
</div>
<script>
// random 100 data points, x in 100..200, y in -120..-50
var data = [];
for(let i = 0; i < 100; i++) data.push([100+i, -50 - Math.random() * 70]);
var xmin = data[0][0], xmax = data[data.length - 1][0], ymin = data[0][1], ymax = data[0][1];
for(let i = 1; i < data.length; i++) { if(data[i][1] < ymin) ymin = data[i][1]; if(data[i][1] > ymax) ymax = data[i][1]; }
// scatter graph with white text, green lines, no ticks
scatter = new RGraph.Scatter({
id: 'cvs',
data: data,
options: {
backgroundGridDotted: true,
marginLeft: 60,
marginBottom: 50,
line: true,
tickmarksStyle: null,
textColor: 'white',
xaxisScale: true,
xaxisScaleMin: xmin,
xaxisScaleMax:xmax,
xaxisColor: 'white',
xaxisTitle: 'Frequency (MHz)',
yaxisScaleMin: ymin,
yaxisScaleMax: ymax,
yaxisColor: 'white',
yaxisTitle: 'Received Power Level (dBm)',
xaxis: false,
yaxisTickmarksLastBottom: false
}
}).trace();
new RGraph.Drawing.XAxis({
id: 'cvs',
y: scatter.canvas.height - scatter.marginBottom,
options: {
xaxisLabels: ['Rich','Alex','Johnny','Kev','Pete','Luis','John','Barry'],
xaxisTickmarksCount: 8,
xaxisColor: 'white',
marginLeft: scatter.get('marginLeft'),
marginRight: scatter.get('marginRight'),
xaxisTickmarksLastLeft: false
}
}).draw();
</script>
当我的 Y 值为负时,我无法在散点图底部显示 X 轴。 X 轴一直显示在 canvas 的顶部边缘(同时 X 标签正确定位)。
下面使用的 JS 代码,canvas 周围的 div 具有黑色背景,这就是轴和标签为白色的原因。谁能告诉我我错过了什么吗? (我是 RGraph 的新手,这是我的第一次试用)。
谢谢哔叽
// random 100 data points, x in 100..200, y in -120..-50
var data = [];
for(let i = 0; i < 100; i++) data.push([100+i, -50 - Math.random() * 70]);
var xmin = data[0][0], xmax = data[data.length - 1][0], ymin = data[0][1], ymax = data[0][1];
for(let i = 1; i < data.length; i++) { if(data[i][1] < ymin) ymin = data[i][1]; if(data[i][1] > ymax) ymax = data[i][1]; }
// scatter graph with white text, green lines, no ticks
var chart = new RGraph.Scatter({
id: 'chart',
data: data,
options: { backgroundGridDotted: true, marginLeft: 60, marginBottom: 50, line: true, tickmarksStyle: null, textColor: 'white',
xaxisScale: true, xaxisScaleMin: xmin, xaxisScaleMax:xmax, xaxisColor: 'white', xaxisTitle: 'Frequency (MHz)',
yaxisScaleMin: ymin, yaxisScaleMax: ymax, yaxisColor: 'white', yaxisTitle: 'Received Power Level (dBm)'
}
}).draw();
试试这个:
https://codepen.io/rgraph/full/QWKbRwr
(使用“更改视图”按钮查看代码)
<script src="https://www.rgraph.net/libraries/RGraph.common.core.js"></script>
<script src="https://www.rgraph.net/libraries/RGraph.drawing.xaxis.js"></script>
<script src="https://www.rgraph.net/libraries/RGraph.scatter.js"></script>
<div style="display: inline-block; background-color: black">
<canvas id="cvs" width="600" height="250"></canvas>
</div>
<script>
// random 100 data points, x in 100..200, y in -120..-50
var data = [];
for(let i = 0; i < 100; i++) data.push([100+i, -50 - Math.random() * 70]);
var xmin = data[0][0], xmax = data[data.length - 1][0], ymin = data[0][1], ymax = data[0][1];
for(let i = 1; i < data.length; i++) { if(data[i][1] < ymin) ymin = data[i][1]; if(data[i][1] > ymax) ymax = data[i][1]; }
// scatter graph with white text, green lines, no ticks
scatter = new RGraph.Scatter({
id: 'cvs',
data: data,
options: {
backgroundGridDotted: true,
marginLeft: 60,
marginBottom: 50,
line: true,
tickmarksStyle: null,
textColor: 'white',
xaxisScale: true,
xaxisScaleMin: xmin,
xaxisScaleMax:xmax,
xaxisColor: 'white',
xaxisTitle: 'Frequency (MHz)',
yaxisScaleMin: ymin,
yaxisScaleMax: ymax,
yaxisColor: 'white',
yaxisTitle: 'Received Power Level (dBm)',
xaxis: false,
yaxisTickmarksLastBottom: false
}
}).trace();
new RGraph.Drawing.XAxis({
id: 'cvs',
y: scatter.canvas.height - scatter.marginBottom,
options: {
xaxisLabels: ['Rich','Alex','Johnny','Kev','Pete','Luis','John','Barry'],
xaxisTickmarksCount: 8,
xaxisColor: 'white',
marginLeft: scatter.get('marginLeft'),
marginRight: scatter.get('marginRight'),
xaxisTickmarksLastLeft: false
}
}).draw();
</script>