Javascript Google折线图-轴0的数据列不能为字符串类型
我正在使用谷歌开发者提供的折线图API 当我尝试绘制图形时,它给我轴0的错误数据列不能是字符串类型。我已经研究了堆栈溢出的其他解决方案,但仍然无法解决它。有什么建议吗Javascript Google折线图-轴0的数据列不能为字符串类型,javascript,arrays,Javascript,Arrays,我正在使用谷歌开发者提供的折线图API 当我尝试绘制图形时,它给我轴0的错误数据列不能是字符串类型。我已经研究了堆栈溢出的其他解决方案,但仍然无法解决它。有什么建议吗 <script> var myarray = [['variable x','variable y']]; function addInputs () { myarray.push([xInput.value,yInput.value]); } function graphPlot
<script>
var myarray = [['variable x','variable y']];
function addInputs () {
myarray.push([xInput.value,yInput.value]);
}
function graphPlot () {
google.setOnLoadCallback();
console.log("Graph is plotted!");
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
var data = google.visualization.arrayToDataTable(myarray);
var options = {
title: 'Linear Regression Chart',
curveType: 'none',
legend: { position: 'bottom' }
};
chart.draw(data, options);
}
//Button send in input values into the myArray.
enterButton.addEventListener('click',addInputs);
//Button plots the graph
plotGraph.addEventListener('click',graphPlot);
</script>
通过将文本更改为浮点值,我解决了这个问题
myarray.push([parseFloat(xInput.value),parseFloat(yInput.value)]);
但是我在index.html中的输入是number类型。为什么取而代之的是字符串值
<html>
<input type="number" step="0.1" id="xInput"/>
<input type="number" step="0.1" id="yInput"/>
</html>
我的xInput和yInput来自文本框,属于浮点数类型。i、 e 5.0。