Мультипанель на Хайсток - PullRequest
0 голосов
/ 22 марта 2019

Я пытаюсь создать двухпанельную биржевую диаграмму с использованием высоких графиков, подобных приведенному здесь http://www.highcharts.com/stock/demo/candlestick-and-volume/grid-light

Я храню свой файл JSON здесь https://api.jsonbin.io/b/5c9499db08b9a73c3abeec4a.

Когда язапустил мой проект, я не знаю, почему эти данные не работают должным образом, и десятичное значение становится больше, и как синхронизировать временные ряды с моей серией GMT 7+.

И вот мой проект:

$.getJSON('https://api.jsonbin.io/b/5c9499db08b9a73c3abeec4a', function (data) {

       var  X 		= [],
   		 Y       = [],
        temperature  = [],
        dataLength = data.length,
        
        // set the allowed units for data grouping
        groupingUnits = [[
            'week',                         // unit name
            [1]                             // allowed multiples
        ], [
            'month',
            [1, 2, 3, 4, 6]
        ]],

        i = 0;

    for (i; i < dataLength; i += 1) {
        X.push([
            data[i][0], // the date
            data[i][1]  // the X
        ]);
        Y.push([
            data[i][0], // the date
            data[i][2]  // the Y
        ]);

        temperature.push([
            data[i][0], // the date
            data[i][3] // the temp
        ]);
    }


    // create the chart
    Highcharts.stockChart('container', {

        rangeSelector: {
            selected: 1
        },

        title: {
            text: 'AAPL Historical'
        },

        yAxis: [{
            labels: {
                align: 'right',
                x: -3
            },
            title: {
                text: 'X'
            },
            height: '60%',
            lineWidth: 2,
            resize: {
                enabled: true
            }
        }, {
            labels: {
                align: 'right',
                x: -3
            },
            title: {
                text: 'temp'
            },
            top: '65%',
            height: '35%',
            offset: 0,
            lineWidth: 2
        }],

        tooltip: {
            split: true
        },

        series: [
        {
            type: 'line',
            name: 'X',
            data: X,
            dataGrouping: {
                units: groupingUnits
            }
        },
        {
            type: 'line',
            name: 'Y',
            data: Y,
            dataGrouping: {
                units: groupingUnits
            }
        },
         {
            type: 'line',
            name: 'temp',
            data: temperature,
            yAxis: 1,
            dataGrouping: {
                units: groupingUnits
            }
        }]
    });
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/drag-panes.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>


<div id="container" style="height: 400px; min-width: 310px"></div>

1 Ответ

1 голос
/ 22 марта 2019

Вы определили неверный массив dataGrouping.units относительно ваших данных.Посмотрите приведенный ниже пример.

Код:

$.getJSON('https://api.jsonbin.io/b/5c9499db08b9a73c3abeec4a', function(data) {

  var X = [],
    Y = [],
    temperature = [],
    dataLength = data.length,
    groupingUnits = [
      [
        'millisecond', // unit name
        [1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
      ],
      [
        'second', [1, 2, 5, 10, 15, 30]
      ],
      [
        'minute', [1, 2, 5, 10, 15, 30]
      ],
      [
        'hour', [1, 2, 3, 4, 6, 8, 12]
      ],
      [
        'day', [1]
      ],
      [
        'week', [1]
      ],
      [
        'month', [1, 2, 3, 4, 6]
      ],
      [
        'year',
        null
      ]
    ],
    i = 0;

  for (i; i < dataLength; i += 1) {
    X.push([
      data[i][0], // the date
      data[i][1] // the X
    ]);
    Y.push([
      data[i][0], // the date
      data[i][2] // the Y
    ]);

    temperature.push([
      data[i][0], // the date
      data[i][3] // the temp
    ]);
  }

  // create the chart
  Highcharts.stockChart('container', {

    yAxis: [{
      labels: {
        align: 'right',
        x: -3
      },
      title: {
        text: 'X'
      },
      height: '60%',
      lineWidth: 2,
      resize: {
        enabled: true
      }
    }, {
      labels: {
        align: 'right',
        x: -3
      },
      title: {
        text: 'temp'
      },
      top: '65%',
      height: '35%',
      offset: 0,
      lineWidth: 2
    }],

    tooltip: {
      split: true
    },

    plotOptions: {
      series: {
        dataGrouping: {
          units: groupingUnits
        }
      }
    },

    series: [{
        name: 'X',
        data: X
      },
      {
        name: 'Y',
        data: Y
      },
      {
        name: 'temp',
        data: temperature,
        yAxis: 1
      }
    ]
  });
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/drag-panes.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>

Демо:

Ссылка API:

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...