为了账号安全,请及时绑定邮箱和手机立即绑定

无法将数组值输入到图表中

无法将数组值输入到图表中

繁星淼淼 2023-09-28 15:50:08
我正在使用 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 那么我确实会得到结果。
查看完整描述

1 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

添加我之前的评论后,我一直在玩这个,你也可以这样做(这已经满足了):

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}}

]);


查看完整回答
反对 回复 2023-09-28
  • 1 回答
  • 0 关注
  • 51 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信