Home > Back-end >  what is output format of Utils? (using chartjs in vanillajs, not react/angular)
what is output format of Utils? (using chartjs in vanillajs, not react/angular)

Time:05-24

I'm trying to load data for a bubbles chart from datafiles, the examples use a chartjs function to generate data.

Working through some of the examples, want to load csv/json files via d3.js as will be using data files from an api and front end not in react/angular.

examples so far. https://github.com/aspiringguru/chartjs_3.7.1_vanilla

I can't see the output format of Utils.* used in the examples.

expecting will need x,y,radius for each point. just need to work out what format chartjs expects the data in.

https://www.chartjs.org/docs/next/samples/other-charts/bubble.html uses

data: Utils.bubbles(NUMBER_CFG)

dataset.data = Utils.bubbles({count: chart.data.labels.length, rmin: 5, rmax: 15, min: 0, max: 100});

had a look at https://github.com/chartjs/Chart.js/blob/master/docs/scripts/utils.js and I can't understand the output generated from

function bubbles(config)

CodePudding user response:

As can be read here in the documentation. The datastructure for bubble charts consists out of an array containing objects where each object has an x key for the x value, an y key for the y value and a r key for the radius.

{
    // X Value
    x: number,

    // Y Value
    y: number,

    // Bubble radius in pixels (not scaled).
    r: number
}
const data = [{x: 5, y: 7, r: 9}, {x: 6, y: 3, r: 1}];
  • Related