I'm trying to create a Component that takes charts and chartHeight as props, and returns a Highstock Chart with multiple series based on the given props.charts array.
When I create the options for the chart like so:
Code: Select all
setChartOptions({
chart: {
height: (props.charts.length) * props.chartHeight,
},
credits: {
enabled: false
},
title: {
text: 'Title'
},
rangeSelector: {
selected: 0,
buttons: [],
inputEnabled: false
},
tooltip: {
split: true
},
series: buildSeries(),
yAxis: buildYAxis()
})
Code: Select all
const buildSeries = () => {
let series = [];
props.charts.forEach((chart, index) => {
series.push({
type: chart.type,
name: chart.title,
data: chart.data,
yAxis: index,
color: chart.color
})
})
return series;
}
const buildYAxis = () => {
let yAxis = [];
props.charts.forEach((chart, index) => {
yAxis.push({
labels: {
align: 'right',
x: -3
},
title: {
text: chart.title,
},
height: props.chartHeight,
top: index * props.chartHeight,
lineWidth: 2,
resize: {
enabled: true
},
offset: 0
})
})
return yAxis;
}
When I paste the return value of buildSeries() and buildYAxis() instead of calling the functions, the chart is displayed correctly as well.
I'm following this example to build my chart: https://www.highcharts.com/demo/stock/c ... and-volume
What am I missing here?
If there's more information needed please let me know