javascript - 无法将数组值输入图形
问题描述
我正在使用 Rgraph 来绘制折线图。我正在尝试使用 Javascript 将值输入图表。
这是例程..
function update_day_temp(newval){
var newval = '6,5,7,3,7,9,10';
var dta = [];
dta = newval.split(',');
console.log('data ' + dta);
day_temp = new RGraph.Line({
id: 'day_temp',
// data: dta,
data: [6,5,7,3,7,9,10],
options: {
}
}).draw()
};
如果我使用所使用的数据,一切都很好。但是,如果我使用 dta,那么我确实会得到结果。
解决方案
添加我之前的评论后,我一直在玩这个,你也可以这样做(已经满足了):
data: '6,5,7,3,7,9,10'.split(','),
这只是将字符串拆分为一个数组,然后通过 RGraph 将值转换为数字。
在 RGraph 的下一个版本(v5.27)中,您将不需要调用 split()。
这里有一个演示,它对数据调用 split() 函数:
https://www.rgraph.net/demos/bar-basic.html
其中的代码是这样的:
new RGraph.Bar({
id: 'cvs',
data: '12,18,10,9,6,20,18'.split(','),
options: {
yaxisScaleUnitsPost: 'k',
colors: ['red'],
title: 'A basic Bar chart using accessible text',
titleBold: true,
xaxis: false,
yaxis: false,
marginLeft: 50,
tooltips: '%{key}',
tooltipsFormattedUnitsPost: '%',
tooltipsCss: {
fontSize: '26pt'
},
tooltipsFormattedKeyLabels: ['Dave','John'],
tooltipsEvent: 'mousemove'
}
}).draw().responsive([
{maxWidth:900,width:400,height:150,options: {textSize:10,xaxisLabels:['Mon\n(yuck!)','Tue','Wed','Thu','Fri\n(woo!)','Sat','Sun'],marginInner: 10}},
{maxWidth:null,width:750,height:250,options: {textSize:14,xaxisLabels: ['Monday\n(yuck!)','Tuesday','Wednesday','Thursday','Friday\n(woo!)','Saturday','Sunday'],marginInner: 20}}
]);
推荐阅读
- python-3.x - 通过http服务器显示html-但是127.0.0.0.1:8008无法连接
- node.js - 我们如何在 express ejs 中显示 flash 消息
- sql - 我在加入两个实体类时遇到问题
- mysql - 插入许多行,LAST_INSERT_ID 返回 1
- swift - SCNShadable 没有动画
- c# - 将 C# 函数传递给 CLI/C++ 代码时出现垃圾收集器错误
- typescript - 如何使用 rxjs 过滤器在每个元素中使用可变数量的类别进行过滤
- c# - ObserveEveryValueChanged 未收到所有更改
- javascript - Angular 7,使用来自对象的一些值创建新对象
- python-3.x - 在使用 COPY 将大表读入 pandas 数据帧时使用参数化 SQL 查询