python-highcharts icon indicating copy to clipboard operation
python-highcharts copied to clipboard

Will not work within a class?

Open Prooffreader opened this issue 10 years ago • 2 comments

As soon as I wrap a working example within a class, nothing displays:

import charts

class Wrapper():
    def __init__(self):
        data = [1,2,5,9,6,3,4,8]
        options = dict(height=400, title=dict(text='My first chart!'))
        charts.plot(data, options=options, name='List data', show='inline')

instance = Wrapper()

Prooffreader avatar Dec 04 '15 18:12 Prooffreader

after reading the source code, we got a solution: Jupyter highcharts在函数里不显示

it may work for your case.

import charts

def foo():
    data = [1,2,5,9,6,3,4,8]
    options = dict(height=400, title=dict(text='My first chart!'))
    chart = charts.plot(series=data, options=options, name='List data', save='temp.svg', show='inline')
    from IPython.display import HTML
    chart = HTML('<h1>hello world</h1>' + chart.data)
    return {'chart': chart, 'what_ever': 123}

d = foo()
d['chart']

suanfazu avatar May 16 '16 15:05 suanfazu

and another solution: http://suanfazu.com/t/jupyter-highcharts/13438/2

def bar():
    from IPython.display import display
    chart = HTML('<h1>Hello, world!</h1>')
    # or chart = charts.plot(...)
    display(chart)

bar()

suanfazu avatar May 16 '16 16:05 suanfazu