如何在mongodb中存储与highcharts兼容的json数组数据

时间:2021-09-24 02:35:10

I am trying to feed data to highcharts client. Currently highcharts expects data in below format.

我正在尝试将数据提供给highcharts客户端。目前highcharts期望以下格式的数据。

    [
    [1515122457593,47,64.17,12.77,23.91,15969798], 
    [1515122497615,23.91,47.97,14.19,30.81,15969798],     
    [1515122537619,30.81,49.42,13.34,27.76,15969798],...
    ]

However, I could not find a way to store in same format in MongoDB. I think one possibility is as below.

但是,我找不到在MongoDB中以相同格式存储的方法。我认为一种可能性如下。

{
{ "_id": 1, "time":1515122457593, "O":47, "H":64.17, "L":12.77, "C":23.91, "V":15969798 },
{ "_id": 2, "time":1515122497615, "O":23.91, "H":47.97, "L":14.19, "C":30.81, "V":15969798 },
{ "_id": 3, "time":1515122537619, "O":30.81, "H":49.42, "L":13.34, "C":27.76, "V":15969798 },
...
}

My questions are in both directions. Direction 1: How do I make above mongodb friendly json format to be read by Highcharts OHLC. Direction 2: How do I store Highcharts friendly data series in Mongodb?

我的问题是双向的。方向1:如何使Highcharts OHLC读取mongodb友好的json格式。方向2:如何在Mongodb中存储Highcharts友好数据系列?

Kindly share example as I could not find online any snippets that could help and all my trials are in vain. I got a hint here, but could not develop it further for my OHLC format (I am newbie to JS and webdev)

请分享一些例子,因为我无法在网上找到任何可以提供帮助的片段,而且我所有的审判都是徒劳的。我在这里得到了一个提示,但无法为我的OHLC格式进一步开发(我是JS和webdev的新手)

Highcharts.chart('container', {
chart: {
    type: 'column'
},

xAxis: {
    categories: ['Green', 'Pink']
},

series: [{
    data: [{
        name: 'Point 1',
        color: '#00FF00',
        y: 1
    }, {
        name: 'Point 2',
        color: '#FF00FF',
        y: 5
    }]
}]});

1 个解决方案

#1


0  

You should be able to achieve the exact document structure required by Highcharts using the below schema:

您应该能够使用以下架构实现Highcharts所需的确切文档结构:

var schema = new Schema({
  data: [[Number]] // array of array of numbers
})

#1


0  

You should be able to achieve the exact document structure required by Highcharts using the below schema:

您应该能够使用以下架构实现Highcharts所需的确切文档结构:

var schema = new Schema({
  data: [[Number]] // array of array of numbers
})