Brad Mace
Brad Mace

Reputation: 27886

Using Chart.js client-side in Atlasboard

How can a third-party javascript library be made available for client-side use in Atlasboard? require doesn't work in widgets, and I don't want to have to import the whole library into every widget that uses the library.

Upvotes: 0

Views: 536

Answers (1)

Brad Mace
Brad Mace

Reputation: 27886

  1. Place the javascript library file (such as Chart.min.js) in assets/javascripts/.
  2. In the JSON config for the dashboard(s) which will load the widgets that will rely on the library, add the name of the library to the layout.customJS array:

Example:

{
  "title": "My Dashboard",
  "titleVisible": false,

  "description": "a neat dashboard",

  "layout": {
    "gridSize" : { "columns" : 20, "rows" : 12 },
    "customJS" : ["Chart.min.js"],
    "widgets" : [
        ...
    ]
  },

  "config": {
    ...
  }
}

Nothing special needs to be done in the Widget. You can just use the library:

var graph = new Chart(ctx).Radar(data);

Upvotes: 3

Related Questions