【问题标题】:HighChart graphics with node js and react js带有节点 js 和反应 js 的 HighChart 图形
【发布时间】:2021-12-30 09:54:10
【问题描述】:

我正在使用库 highChart https://www.highcharts.com/ 作为统计图表,我想知道是否有可能在不同时期创建不同的数据,例如我有这样的系列:

Categories : [
                '2021-01-01',
                '2021-01-02',
                '2021-01-03',
                '2021-01-04',
                '2021-01-05',
                '2021-01-06',
                '2021-01-07',
                '2021-01-08',
                '2021-01-09',
                '2021-01-10',
                '2021-01-11',
                '2021-01-12',
                '2021-01-13',
                '2021-01-14',
                '2021-01-15',
                '2021-01-16',
                '2021-01-17',
                '2021-01-18',
                '2021-01-19',
                '2021-01-20',
                '2021-01-21',
                '2021-01-22',
                '2021-01-23',
                '2021-01-24',
                '2021-01-25',
                '2021-01-26',
                '2021-01-27',
                '2021-01-28',
                '2021-01-29',
                '2021-01-30',
             ]
series : [
{
    name : 'serie 1',
    data : [
                {x : '2021-01-05' , s : 5},
                {x : '2021-01-10' , s : 20},
                {x : '2021-01-11' , s : 40},
                {x : '2021-01-15' , s : 80},
                {x : '2021-01-30' , s : 20},

           ]
}

] 


i wanna the x values in the graphic get the period in categories and get the x value from series to compare if the x value in series exist then get s value in the series else put 0 
How i can do that in highChart 

【问题讨论】:

    标签: node.js reactjs highcharts


    【解决方案1】:

    我实现了一个将数据解析为所需格式的逻辑。看看这个演示:https://jsfiddle.net/BlackLabel/hrasqo92/

    const parsedData = categories.map(category => {
      const dataPoint = baseData.filter(data => data.x === category);
      if (dataPoint.length) {
        return [category, dataPoint[0].y]
      } else {
        return [category, 0]
      }
    })
    

    【讨论】:

    • 非常感谢它的工作
    猜你喜欢
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 2016-12-06
    • 2019-04-01
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多