我正在尝试为我的项目绘制图表,在x 轴上测量压力并将深度测量为y 轴,即 压力与测量深度 我绘制了错误的图表,使用谷歌图表,如何在图表中互换 x 和 y 轴点值,任何人都可以帮助我们。 我期望这样的输出 下面我发布了我尝试过的代码
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
let jsonData = {
"result": {
"abcData": [
{
"measuredepth": 0,
"pressure": 2500,
}, {
"measuredepth": 0,
"pressure": 2492,
},
{
"measuredepth": 4450,
"pressure": 3259
},
{
"measuredepth": 4500,
"pressure": 3273
}]
}
}
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = new google.visualization.DataTable();
data.addColumn('number', 'md');
// data.addColumn('number', 'CT');
data.addColumn('number', 'WELL');
for (let i = 0; i < jsonData.result.abcData.length; i++) {
debugger;
data.addRows([[jsonData.result.abcData[i].measuredepth, jsonData.result.abcData[i].pressure]]);
}
var options = {
title: 'GRaph-data',
width: 900,
height: 500,
chartArea: {
top: 100
},
vAxis: {
direction: 0
}
};
var chart = new google.visualization.LineChart(document.getElementById('line_top_x'));
//chart.draw(data, options);
google.visualization.events.addListener(chart, 'ready', function () {
var chartLayout = chart.getChartLayoutInterface();
var chartBounds = chartLayout.getChartAreaBoundingBox();
var labels = chart.getContainer().getElementsByTagName('text');
var fontSize;
var yCoord;
Array.prototype.forEach.call(labels, function (label) {
fontSize = parseFloat(label.getAttribute('font-size'));
switch (label.getAttribute('text-anchor')) {
// chart title
case 'start':
yCoord = parseFloat(label.getAttribute('y'));
label.setAttribute('y', yCoord - fontSize);
break;
// x-axis labels
case 'middle':
label.setAttribute('y', chartBounds.top - (fontSize / 2));
break;
// y-axis labels
default:
// ignore
}
});
});
chart.draw(data, options);
}
);
</script>
</head>
<body>
<div id="line_top_x"></div>
</body>
</html>