Using Plotly.js in my React application, I wish to retrieve the "range" array from the layout object. This is what my code looks like:
useEffect(() => {
if (chartData) {
console.log(chartData.layout.yaxis);
console.log(chartData.layout.yaxis.range);
console.log(JSON.stringify(chartData.layout.yaxis));
}
}, [chartData])
Output from console.log(chartData.layout.yaxis):
{
anchor: "x"
autorange: true
domain: (2) [0, 1]
range: (2) [-1611.7268768451163, 15422.563518243458]
title: {text: 'This is a sample text'}
type: "linear"
}
Output from console.log(chartData.layout.yaxis.range):
undefined
Output from console.log(JSON.stringify(chartData.layout.yaxis)):
{"anchor":"x","domain":[0,1],"title":{"text":"This is a sample text"}}
What I can't get my head around is the range is clearly present as an array in the first console.log but comes out as undefined with I try to access it directly in the second console.log.
What is the explanation behind this behavior and how do I retrieve the "range" array, that clearly is there?