2017-02-13 34 views
1

我使用一個官方高架圖表demo來創建類似的東西,並將兩個圖表堆疊在一起。問題是沒有顯示底部圖表(音量)jsfiddleHighstock底部圖表未顯示

aapl-ohlc.json文件的簡要說明將會有所幫助。

...  
const data = JSON.parse(document.getElementById('ohlc-data').innerHTML); 


// split the data set into ohlc and volume 
const ohlc = data.map((a) => [a[0], a[1], a[2], a[3], a[4]]) 
const volume = data.map((a) => [a[0], a[5]]) 

// set the allowed units for data grouping 
const groupingUnits = [ 
    [ 
    'week', // unit name 
    [1] // allowed multiples 
    ], 
    [ 
    'month', [1, 2, 3, 4, 6] 
    ] 
] 

// create the chart 
Highcharts.stockChart('container', { 
    legend: { 
    enabled: false 
    }, 
    credits: { 
    enabled: false 
    }, 
    exporting: { 
    enabled: false 
    }, 
    scrollbar: { 
    enabled: false 
    }, 
    rangeSelector: { 
    selected: 4, 
    inputEnabled: false 
    }, 

    title: { 
    text: '' 
    }, 

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

    tooltip: { 
    split: true 
    }, 

    series: [{ 
    type: 'candlestick', 
    name: 'AAPL', 
    data: ohlc, 
    dataGrouping: { 
     units: groupingUnits 
    } 
    }, { 
    type: 'column', 
    name: 'Volume', 
    data: volume, 
    yAxis: 1, 
    dataGrouping: { 
     units: groupingUnits 
    } 
    }], 
    navigator: { 
    enabled: false 

    } 
}); 

回答

0

這條線:

const volume = data.map((a) => [a[0], a[5]]) 

指向不存在的元素。 a[5]沒有定義(每個子數組只有五個元素,沒有第六個元素),因此數據中沒有y值,因此沒有要顯示的數據系列。

我不知道什麼樣的數據元素應該代表的體積,但參考,只是爲了顯示它的工作,這裏是使用更新的小提琴

const volume = data.map((a) => [a[0], a[1]]) 

編輯:

請注意,在演示的例子,你基於你的小提琴,他們使用的文件是aapl-ohlcv.json,而不是aapl-ohlc.json,它確實在每個子陣列中都有第6個數據元素。