arnoutaertgeerts / python-highcharts

Use highchart.js to make plots in Python and IPython notebooks
http://nbviewer.ipython.org/github/arnoutaertgeerts/python-highcharts/blob/master/Tutorial.ipynb
Other
134 stars 31 forks source link

Will not work within a class? #47

Open Prooffreader opened 8 years ago

Prooffreader commented 8 years ago

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()
suanfazu commented 8 years ago

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 commented 8 years ago

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()