Displaying charts
There are two different ways of displaying the charts:
- In a web browser
- In a Notebook environment
Every chart has a method chart.open(),
in which user can define method argument to use either of these display methods:
import lightningchart as lc
lc.set_license('my-license-key')
chart = lc.ChartXY()
chart.open(method="browser") # "browser" | "notebook"
If method is not defined by the user, it defaults to "browser" if using a normal Python script,
or "notebook" if using a Notebook environment.
When using the Notebook display mode, make sure to call chart.open()
at the very end of your desired code cell, otherwise the chart will not display!
Static & Real-time display mode
chart.open() has another argument; a Boolean value live
If live is set to False (which it is by default), the chart will be rendered as a static one-time display.
This display mode is faster to open, and is more suitable for quick and simple visualization use cases.
If live is set to True, a local server will be started to host the chart temporarily,
and to update it dynamically. This display mode is slightly slower to open, but preservers
the chart until explicitly closed by the user. Any changes made to the chart from Python API
will be automatically applied to the rendering view, without the need to call chart.open() again.
This display mode is meant for any real-time visualization use case.
import lightningchart as lc
lc.set_license('my-license-key')
x = [1, 2, 3, 4]
y = [1, 3, 2, 4]
####################
chart = lc.ChartXY()
series = chart.add_point_series()
chart.open(live=False)
series.add(x, y) # this wwould not show in the render view
####################
chart = lc.ChartXY()
series = chart.add_point_series()
chart.open(live=True)
series.add(x, y) # this will show in the render view
If you want to host a dynamic chart but do not want to use the default display modes,
you can use chart.open(method='link')
This will do the same as chart.open(live=True) except it does not open the rendering view.
Additionally, this function returns the URL (localhost:port) of the dynamic chart.
This URL could for example be used to embed the chart to some custom user interface.
import lightningchart as lc
import webbrowser
lc.set_license('my-license-key')
chart = lc.ChartXY()
url = chart.open(method='link') # get the URL of the live chart
webbrowser.open(url) # open the URL
Closing the real-time chart
When using the real-time display mode, the server hosting the chart will stay on until explicitly closed by the user.
Use chart.close() when you want to close the server and the real-time chart instance.
import lightningchart as lc
lc.set_license('my-license-key')
chart = lc.ChartXY()
series = chart.add_point_series()
chart.open(live=True) # open the live chart
# add the real-time data after the chart has been opened
series.add(
x=[1, 2, 3, 4],
y=[1, 3, 2, 4],
)
chart.close() # close the live chart when finished
chart.close() is not needed when using static display mode.
Appearance
See Themes for different chart appearance options.