gpt4 book ai didi

javascript - LineWidth 不改变谷歌图表

转载 作者:行者123 更新时间:2023-11-29 21:12:54 25 4
gpt4 key购买 nike

如何更改此代码以使 lineWidth 正常工作?

<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<table>
<tr>
<td>k: </td>
<td><input id="k" type="number" value="2.2" min="0" max="10" step="0.1" /></td>
</tr>
<tr>
<td>lambda: </td>
<td><input id="lambda" type="number" value="7.6" min="0" max="10" step="0.1" /></td>
</tr>
</table>

<p id="message"> </p>
<div id="chart_weights"></div>

<script type="text/javascript">
google.charts.load('current', {
'packages': ['line']
}); // load the visualisation API and corechart package
google.charts.setOnLoadCallback(UpdateValues); // set a callback to run when the Google Visualization API is loaded

// Callback that creates and populates a data table, instantiates the chart, passes in the data and draws it.
function drawChart() {
if (!google.visualization) {
return;
}
// Create the data table for the symbol in question.
var data = new google.visualization.DataTable();

data.addColumn('number', '');
data.addColumn('number', 'lambda');

data.addRows(weight);
var options = {
lineWidth: 10,
width: 550,
height: 288,
legend: {
position: 'none'
},
colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f',
'#f6c7b6'
]
};
//data.addRows(number);
//console.log(type(data));

var chart = new google.charts.Line(document.getElementById(
'chart_weights'));
chart.draw(data, options);
}

var weight = [];

function UpdateValues() {
weight = [];
var k = document.getElementById("k").value;
var lambda = document.getElementById("lambda").value;
for (var x = 0.1; x < 20; x++) {
weight.push([x, k * Math.pow(x / lambda, k - 1) * Math.exp(-
Math.pow(x / lambda, k)) / lambda]);
document.getElementById("message").innerHTML = weight;
}
drawChart();
}

UpdateValues();

document.getElementById("k").addEventListener("click", function () {
UpdateValues();
});

document.getElementById("lambda").addEventListener("click", function () {
UpdateValues();
});

</script>
</body>

</html>

最佳答案

正在绘制的图表是Material图表

google.charts.Line --> 'packages': ['line']

有很多选项在 Material 图表上根本不起作用
包括 lineWidth

看到这个问题--> Tracking Issue for Material Chart Feature Parity #2143

改用核心图表

google.visualization.LineChart --> 'packages': ['corechart']

有一个选项可以更改Core 图表的外观,使其与Material

主题:'material'

关于javascript - LineWidth 不改变谷歌图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40886416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com