Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeDelphi

Build Visually Stunning Dashboards And More With Bokeh Python Library In Delphi And C++

Do you want to build an elegant, concise construction of versatile graphics, and affords high-performance interactivity over large or streaming datasets applications in Delphi/C++ builder?  Don’t know where to start with? Don’t worry, with the help of Python4Delphi we can quickly and easily make interactive plots, dashboards, and data applications using Bokeh Python Library. This post helps to understand with sample Python script.

Delphi itself offers a number of advanced charting libraries. TeeChart is a third party chart bundled with the RAD Studio installation. If you have an existing Python application and you need to create charts you could use the Bokeh library or you could send the data to Delphi and create the chart there. Alternately, you could create the chart via Bokeh and then display it in the Delphi Windows GUI app. You can use Python4Delphi a number of different ways such as:

  • Create a Windows Python GUI around you existing Python app.
  • Add Python scripting to your Delphi Windows apps.
  • Add parallel processing to your Python apps through Delphi threads.
  • Enhance your speed sensitive Python apps with functions from Delphi for more speed.

Prerequisites.

  • If not python and Python4Delphi is not installed on your machine, Check this, how to run a simple python script in Delphi application using Python4Delphi sample app
  • Open windows open command prompt, and type pip install -U bokeh to install Bokeh. For more info for Installing Python Modules check here
  • First, run the Demo1 project for executing Python script in Python for Delphi. Then load the script in the Memo1 field and press the Execute Script button to see the result. Go to GitHub to download the Demo1 source.

Bokeh is an interactive visualization library for modern web browsers. Bokeh exposes two interface levels to users:

  • bokeh.modelslow-level interface that provides the most flexibility to application developers.
  • bokeh.plottinghigher-level interface centered around composing visual glyphs.

Bokeh Python Library sample script details: Plotting data in basic Python lists as a line plot, including zoom, pan, save, and other tools, is simple and straightforward:

  • Prepare some data, In this case, plain Python lists, but NumPy arrays or Pandas series also work.
  • Generate output using output_file() with the filename “lines.html”. Another option is output_notebook() for use in Jupyter notebooks.
  • Call figure() this creates a plot with typical default options and easy customization of title, tools, and axes labels.
  • Add renderers like line()  for our data, specifying visual customizations like colors, legends, and widths.
  • Ask Bokeh to show() or save() the results. These functions save the plot to an HTML file and optionally display it in a browser.

Steps three and four can be repeated to create more than one plot.

  • When you execute this script, you will see that a new output file “lines.html” is created and that a browser automatically opens a new tab to display it (for presentation purposes we have included the plot output directly inline in this document).
bokeh_plot-1-9265259
Bokeh Python Library Demo

Note: Samples used for demonstration were picked from here. You can much more with this library from Providing Data Directly, Creating Layouts, Visualizing Network Graphs, and much more. You can check the APIs and some more samples from the same place. It’s mandatory to include the below code to avoid exceptions. To know more about MaskFPUExceptions check here.

You have read the quick overview of Bokeh library, download this library from here and build your dashboards, interactive plots in your applications. Check out Python4Delphi and easily build Python GUIs for Windows using Delphi.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES