Table of Contents
YOUR_PATH/fusionexportWhen the server runs, you’ll see the following screen:
npm install fusionexport-node-client --save
[ { "type": "column2d", "renderAt": "chart-container", "width": "500", "height": "300", "dataFormat": "json", "dataSource": { "chart": { "caption": "Monthly Admissions In Horton General Hospital", "subcaption": "Source: UCI Machine Learning Repository", "xaxisname": "Month/Year", "yaxisname": "Number of Admissions", "showvalues": "0", "theme": "fusion" } } }, { "type": "splinearea", "renderAt": "area-chart-container", "width": "550", "height": "300", "dataFormat": "json", "dataSource": { "chart": { "caption": "Monthly Admissions In Horton General Hospital", "subcaption": "Source: UCI Machine Learning Repository", "xaxisname": "Month/Year", "yaxisname": "Number of Admissions", "showvalues": "0", "theme": "fusion" } } }, { "type": "doughnut2d", "renderAt": "pie-chart-container", "width": "550", "height": "300", "dataFormat": "json", "dataSource": { "chart": { "caption": "Monthly Admissions First Six Months In 2000", "subcaption": "Source: UCI Machine Learning Repository", "xaxisname": "Month/Year", "yaxisname": "Number of Admissions", "showvalues": "0", "theme": "fusion" } } }, { "type": "line", "renderAt": "line-chart-container", "width": "550", "height": "300", "dataFormat": "json", "dataSource": { "chart": { "caption": "Monthly Admissions In Horton General Hospital", "subcaption": "Source: UCI Machine Learning Repository", "xaxisname": "Month/Year", "yaxisname": "Number of Admissions", "yaxismaxvalue": "5", "showvalues": "0", "theme": "fusion" } } } ]
<html> <head> <title>Exporting FusionCharts in Node.js</title> <style> body { margin: 0; padding: 0; width: 100%; background-color: #00406a; font-family: Tahoma, Helvetica, Arial, sans-serif; } h1, h2, h3, h4, h5 { margin: 0; padding: 0; font-weight: bold; text-align: center; } .chartCont { padding: 0px 12px; } .border-bottom { border-bottom: 1px dashed rgba(0, 117, 194, 0.2); } .border-right { border-right: 1px dashed rgba(0, 117, 194, 0.2); } #container { width: 1200px; margin: 0 auto; position: relative; } #container > div { width: 100%; background-color: #ffffff; } #logoContainer { float: left; } #logoContainer img { padding: 0 10px; } #logoContainer div { position: absolute; top: 8px; left: 95px; } #logoContainer div h2 { color: #0075c2; } #logoContainer div h4 { color: #0e948c; } #logoContainer div p { color: #719146; font-size: 12px; padding: 5px 0; } #userDetail { float: right; } #userDetail img { position: absolute; top: 16px; right: 130px; } #userDetail div { position: absolute; top: 15px; right: 20px; font-size: 14px; font-weight: bold; color: #0075c2; } #userDetail div p { margin: 0; } #userDetail div p:nth-child(2) { color: #0e948c; } #header div:nth-child(3) { clear: both; border-bottom: 1px solid #0075c2; } #content div { display: inline-block; } #content > div { margin: 0px 20px; } #content > div:nth-child(1) > div { margin: 20px 0 0; } #content > div:nth-child(2) > div { margin: 0 0 20px; } #footer p { margin: 0; font-size: 9pt; color: black; padding: 5px 0; text-align: center; } </style> </head> <body> <div id="container"> <div id="header"> <div id="logoContainer"> <img src="https://archive.ics.uci.edu/ml/assets/logo.gif" alt="Logo" /> <div> <h2></h2> <h4></h4> </div> </div> <div id="userDetail"> </div> <div></div> </div> <div class="border-bottom" id="content"> <div class="border-bottom"> <div class="chartCont border-right" id="chart-container"> FusionCharts will load here. </div> <div class="chartCont" id="area-chart-container"> FusionCharts will load here. </div> </div> <div> <div class="chartCont border-right" id="pie-chart-container"> FusionCharts will load here. </div> <div class="chartCont" id="line-chart-container"> FusionCharts will load here. </div> </div> </div> <div id="footer"> <p> This application was built using <a href="https://www.fusioncharts.com" target="_blank" title="FusionCharts - Data to delight... in minutes" ><b>FusionCharts Suite XT</b></a > </p> </div> </div> </body> </html>
"1",1,0,0,413,1999,11 "2",1,0,0,443,1999,12 "3",1,0,0,378,2000,1 "4",0,0,0,385,2000,2The 6th and 7th columns show the year and month. The 5th column is the admissions column that shows the count of people entering the emergency. We’ll construct the data JSON object with label keys as month/year and the value as the number of admissions. The exportDashboard.js file implements the following steps:
// Import 'path' and 'fs' core module of Node.js const path = require('path'); const fs = require('fs'); const fetch = require('node-fetch'); const https = require('https'); // Import FusionExport SDK client for Node.js const { ExportManager, ExportConfig } = require('fusionexport-node-client'); uciRepo = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00549/HortonGeneralHospital.csv'; let txt = [] // Fetch the data from UCI ML Repo async function readUciData(){ return await fetch(uciRepo) .then(res => res.text()) } // Convert the downloaded data into JSON async function getData(){ txt = await readUciData(); var data = []; var rows = txt.split("\n"); //Get only the first 30 rows for(var i=1;i<30;i++) { var cols = rows[i].split(','); var obj = {label:cols[6].concat('/', cols[5]), value:cols[4]} data.push(obj); } return data; } async function exportDash() { // Get the data JSON data = await getData(); // Read the configurations for the dashboard let jsonStr = fs.readFileSync("resources/dash-config-file.json", "utf8"); let fcConfig = JSON.parse(jsonStr); // Set the data object in charts read in fcConfig var for (var i=0;i<fcConfig.length;++i) { //special case for doughnut chart if (i==2) { doughnut = []; for (var j=2;j<8;++j) doughnut.push(data[j]); fcConfig[i].dataSource["data"] = doughnut } else fcConfig[i].dataSource["data"] = data; } // --- EXPORT CONFIG --- // Instantiate ExportConfig const exportConfig = new ExportConfig(); exportConfig.set('chartConfig', fcConfig); exportConfig.set('templateFilePath', path.join('resources', 'dashboard-template.html')); // --- EXPORT-MANAGER --- // Instantiate ExportManager const exportManager = new ExportManager(); // --- OUTPUT --- // Export the chart exportManager.export(exportConfig, outputDir = '.', unzip = true).then((exportedFiles) => { exportedFiles.forEach(file => console.log(file)); }).catch((err) => { console.log(err); }); } exportDash();
node exportDashboard.jsOnce the code runs, you’ll see the export.pdf file in the code directory. That’s it! We just exported a dashboard as PDF in 5 easy steps. Head over and download the full source code for this Javascript dashboard.
Ever had a data set that seemed more complicated than a Rubik's cube? You’re not…
We’ve all seen them in textbooks or presentations—those overlapping circles that simplify complex information into…
We’re excited to announce the upcoming release of FusionCharts v4.1—a groundbreaking step forward in the…
Have you ever been overwhelmed by a massive data set and wondered, "How do I…
If you’ve ever tried to make sense of the stock market, you’ve probably come across…
Imagine you’re comparing the sales performance of your top product lines across different regions, or…