Table of Contents
What is FusionExport?
FusionExport allows users to convert charts and dashboards to PDF files or as digital images. In addition to exporting a live dashboard in its current state, with FusionExport, you can also add new elements like your company logo to an object. FusionExport is simple to install and works with all JavaScript charting libraries, e.g., FusionCharts, HighCharts, d3, Chart.js, etc. The SDKs for various programming languages are also available. So user can export charts using languages such as Java, Node.js, C#, Go, and much more.How Do I Export A FusionChart Object From Python?
Exporting a chart from Python is easy. For this blog, we have created a 2D bar chart of the population density of different continents. We’ll export this chart as the .png file shown below.Step 1: Download FusionExport Server
Download the FusionExport server for your OS from the FusionExport website.Step 2: Run the server
Find the location of the installed server and run it by typing at the console, making sure to replace YOUR_PATH with the location of the server:YOUR_PATH/fusionexportIf the server runs successfully, you will see the following:
Step 3: Install FusionExport SDK for Python
Assuming that you have Python installed on your machine, you can install the FusionExport SDK by typing the following at the command line:pip install fusionexport
Step 4: Create the Chart Configuration File
Create a file by the name of chart-config-file.json and copy the following code to it:[{ "type": "column2d", "renderAt": "chart-container", "width": "550", "height": "350", "dataFormat": "json", "dataSource": { "chart": { "caption": "Population Density Per Square Mile", "subCaption": "Source: https://www.geographyrealm.com/continents-population-density/", "theme": "fusion" }, "data": [ { "label": "Africa", "value": "87" }, { "label": "Asia", "value": "246" }, { "label": "Australia", "value": "8.3" }, { "label": "Europe", "value": "188" }, { "label": "North America", "value": "57" }, { "label": "South America", "value": "57" } ] } }]
Step 5: Create Python File
Create the export_chart.py file, and copy the following code to it. Each step of the process is also commented in the code below.# Import sdk from fusionexport import ExportManager, ExportConfig # Import json library import json # Load the JSON chart configuration file chart_json_file = open('chart-config-file.json') config = json.load(chart_json_file) # Instantiate the ExportConfig class and add the required configurations export_config = ExportConfig() export_config["chartConfig"] = config # Various options are: 'png', 'jpeg' 'pdf' and 'svg' export_config["type"] = 'png' # Port and host of FusionExport Service export_server_host = "127.0.0.1" export_server_port = 1337 # Instantiate the ExportManager class export_manager = ExportManager(export_server_host, export_server_port) # Call the export() method with the export_config as an argument export_manager.export(export_config, output_dir = ".", unzip = True)
How Do I Run The Code?
You can run the code by typing at the console:python export_chart.pyThat’s it! Running the line of code above creates a file export.png containing the specified chart. Download the full source code for the FusionExport example with Python on GitHub.