to_js_literal() – returns null for "open" values in data array

Question:

I am trying to convert a chart with a time series to js literal in highcharts for python.

The time series seems to be loading correctly into the python object chart.

When converting to js literal (js_lit), in the data array, "open" values are both null (expected 20 and 21) see error in final line of code below.

Not sure if I’m doing something wrong, but I have not found the error.

Version info:
python 3.12, highcharts-core==1.4.0, highcharts-stock==1.4.0

from highcharts_stock.chart import Chart
ohlcv = [[1665504000000, 20, 21, 19, 20, 322],
         [1665590400000, 21, 23, 21, 22, 168]]
chart = Chart.from_array(ohlcv, series_type='candlestick')

print(chart.options.series[0].data)
# Output: [CandlestickData(open = 20, close = 20, high = 21, low = 19, x = 1665504000000),
# CandlestickData(open = 21, close = 22, high = 23, low = 21, x = 1665590400000)]

js_lit = chart.to_js_literal()
print(js_lit[js_lit.find("data:"):js_lit.find(']]') + 2].replace('n', ''))
# Output: data: [[1665504000000, null, 21, 19, 20], [1665590400000, null, 23, 21, 22]]
Asked By: PetarMignon

||

Answers:

This turned out to be a bug introduced in Highcharts Stock for Python v.1.4.0. It has now been resolved in the newly-released v.1.4.1. Please feel free to upgrade using pip install --upgrade highcharts-stock and try again – should hopefully work now.

Answered By: Chris Modzelewski
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.