javascript - Plotly.js - 更改对象属性内的值
问题描述
我是一个真正的 javascript 初学者,并且有一个项目需要使用 Plotly.js 来可视化图表中的数据。我目前正在学习制作基本条形图。这是我的代码:
HTML
<head>
<script src='https://cdn.plot.ly/plotly-2.4.2.min.js'></script>
</head>
<body>
<input type="checkbox" id="cb15">2015
<input type="checkbox" id="cb16">2016
<input type="checkbox" id="cb17">2017
<div id='grafik'></div>
</body>
Javascript
var data = [
{
x: ['Banyumanik', 'Gunungpati', 'Mijen', 'Tembalang'],
y: [18, 29, 20, 23],
type: 'bar',
width: '0.5',
marker: {
color: 'red'
}
}
];
function switchBar() {
var cb15 = document.getElementById('cb15');
var cb16 = document.getElementById('cb16');
var cb17 = document.getElementById('cb17');
if (cb15.checked) {
data[0].y = [19,25,16,21];
} else if (cb16.checked) {
data[0].y = [10,23,7,20]
} else if (cb17.checked) {
data[0].y = [21,17,14,26]
}
}
Plotly.newPlot('grafik', data);
任何人都可以帮助我如何使我的条形图根据选中的复选框更改值吗?非常感谢您提前。
解决方案
推荐阅读
- python - PEP 符合模块调试
- c# - EventListener 有效负载收集规范
- c++ - 为我自己的操作系统创建 SDK/API(用于应用程序开发)
- node.js - 我在 express next(argument) 中传递一个参数,以便 express 中间件函数会捕获它,但为什么它也会通过 app.all("*")))
- laravel - 密码重置电子邮件通知在真实服务器 Laravel 8 中不起作用
- c++ - 如果我将源文件包含到头文件中,为什么不会出现链接错误?
- flutter - 检查Json响应中的空值是否颤动
- spring-mvc - Bean 名称“adDto”的 BindingResult 和普通目标对象都不能用作请求属性
- windows - 如何在 Windows 命令行中编写循环?
- mesh - Meshlab 可以导出网格中每个点/顶点的曲面曲率吗?