Highcharts Server

Highcharts Server #

This doc explains how to set up a highcharts server in EC2 instance.

Setup #

Create instance #

Create a t4g.large instance. Connect to it using Session Manager.

Install dependencies #

These are required for the browser to run.

sudo apt update && sudo apt install -y \
  ca-certificates \
  fonts-liberation \
  libasound2t64 \
  libatk-bridge2.0-0 \
  libatk1.0-0 \
  libc6 \
  libcairo2 \
  libcups2 \
  libdbus-1-3 \
  libexpat1 \
  libfontconfig1 \
  libgbm1 \
  libgcc-s1 \
  libglib2.0-0 \
  libgtk-3-0 \
  libnspr4 \
  libnss3 \
  libpango-1.0-0 \
  libpangocairo-1.0-0 \
  libstdc++6 \
  libx11-6 \
  libx11-xcb1 \
  libxcb1 \
  libxcomposite1 \
  libxcursor1 \
  libxdamage1 \
  libxext6 \
  libxfixes3 \
  libxi6 \
  libxrandr2 \
  libxrender1 \
  libxss1 \
  libxtst6 \
  lsb-release \
  wget \
  xdg-utils

Setting up the server #

Go to the root directory sudo bash cd ~

Download nvm

source ~/.bashrc

Download npm 22, it is the latest stable version as of writing this. This can be found on the nodejs website.

  • nvm install 22

Clone the highcharts repo

git clone https://github.com/highcharts/node-export-server.git

Go to the repo directory

cd node-export-server

Change browser to Firefox #

Note: We are using Firefox as the browser because Chrome does not work with ARM based instances.

Update lib/browser.js and replace the launchOptions object as below. This is required to use Firefox as the browser.

const launchOptions = {
  browser: "firefox",
  headless: true,
  userDataDir: puppeteerOptions.tempDir || "./tmp/",
  args: ["--no-sandbox", "--disable-setuid-sandbox"],
  dumpio: true,
  handleSIGINT: false,
  handleSIGTERM: false,
  handleSIGHUP: false,
  waitForInitialPage: false,
  defaultViewport: null,
  ...(enabledDebug && debugOptions),
};

Update puppeteer version to 24.12.1 in package.json

"puppeteer": "^24.12.1"

Remove optimizeForSpeed: true, from lib/export.js as it is not supported while using Firefox as browser.

Install dependencies #

npm install

Run the server (optional) #

You can start the server manually for testing:

npm start

Create a systemd service #

To ensure the Highcharts Export Server runs continuously and starts on boot, create a systemd service.

Create the service file:

vi /etc/systemd/system/highcharts-server.service

Add the following content to the file:

[Unit]
Description=Highcharts Export Server
After=network.target

[Service]
WorkingDirectory=/root/node-export-server
ExecStart=/root/.nvm/versions/node/v22.17.0/bin/node ./bin/cli.js --enableServer 1 --logLevel 2
Restart=always
User=root
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

NOTE: Replace the path to the node binary in the ExecStart line by checking same with which node command.

Start the service #

Reload the systemd daemon, enable the service to start on boot, and then start the service:

sudo systemctl daemon-reload
sudo systemctl enable highcharts-server.service
sudo systemctl start highcharts-server.service
sudo journalctl -u highcharts-server.service -f

The last command (journalctl) will display the service logs in real-time, allowing you to monitor its status. You can stop viewing the logs by pressing Ctrl+C.

Test the server #

To test if the Highcharts Export Server is running correctly, execute the following curl command. Please ensure that the address is correct. Current IP of the instance is 172.31.16.159:7801

curl 'http://172.31.16.159:7801' \
  -H 'content-type: application/json' \
  --data-raw '{"infile":"{\n    \"title\": {\"text\": \"Test Chart\"},\n    \"xAxis\": {\"categories\": [\"Jan\", \"Feb\", \"Mar\"]},\n    \"series\": [{\"data\": [29.9, 71.5, 106.4]}]\n  }","width":false,"scale":false,"constr":"chart","type":"image/jpeg","b64":true}'

If it works, you will get a text response which contains the base64 encoded image.

Note: While running the command locally, you need to ensure that you have zero trust enabled and the instance is accessible from your local machine.