Skip to content

Create Charts in JavaScript

This document shows you how to install the FroalaCharts library and all the other dependencies on your system and render a chart using Plain JavaScript.

Prerequisites

If you are using Froalacharts dependencies from CDN or Local Files, you can skip to the next section.

If you choose to install the froalacharts package via npm, make sure you have Node.js installed in your system. Make sure you have a bundler like webpack and parcel or have browserify installed in your system.

Installation and including dependencies

You can install the froalacharts components following any of the methods below:

Preparing the data

Let's create a chart showing a "Comparison of Quarterly Revenue".

Since we are plotting a single dataset, create a column chart with 'Quarter' as data labels along the x-axis and 'Revenues (In USD)' as data values along y-axis.

Quarter Revenues
Q1 10000
Q2 11500
Q3 12500
Q4 15000

FroalaCharts accepts the data in JSON format. The data for the chart is represented in the following way:

const chartData = [
{
  data: [
  {
    value: "10000",
  },
  {
    value: "11500",
  },
  {
    value: "12500",
  },
  {
    value: "15000",
  }]
}];

Configure your chart

Next, work on the styling, positioning and giving your chart a context.

// Create a JSON object to store the chart configurations
const chartConfig = {
  //Specify the chart type
  type: "column",
  //Set the container object
  renderAt: "ft",
  //Specify chart dimensions
  width: "800",
  height: "500",
  //Set the type of data
  dataSource: {
    chart: {
      //Set the theme for your chart
      theme: "froala",
      //Set the chart caption
      caption: "Comparison of Quarterly Revenue",
      //Set the x-axis name
      xAxisname: "Quarter",
      //Set the y-axis name
      yAxisName: "Revenues (In USD)",
      numberPrefix: "$",
    },
    categories: [
      {
        category: [
          {
            label: "Q1",
          },
          {
            label: "Q2",
          },
          {
            label: "Q3",
          },
          {
            label: "Q4",
          }
        ]
      }
    ],
    dataset: chartData
  }
};

Find the complete list of chart types with their respective alias here.

Render the chart

The consolidated code to render the chart is shown below:

See your chart

You should be able to see the chart as shown below.

Froala Charts will load here!

Next Steps

Explore the List of Charts.

Dive into the API documentation.

Learn about other Concepts.

File: 11145