Create a chart with custom data


#1

Hello, I have an array with custom data and I want to use it in a bar chart, is it possible to do it without providers? This is the array:

const data = [
  {country: 'Afghanistan', population_urban: 26, world_share: 0.53, median_age: 17, density: 65, …},
  {country: 'Albania', population_urban: 67, world_share: 0.04, median_age: 38, density: 103, …},
  {country: 'Algeria', population_urban: 75, world_share: 0.57, median_age: 28, density: 19, …},
  {country: 'American Samoa', population_urban: 0, world_share: 0, median_age: 29, density: 220, …},
  {country: 'Andorra', population_urban: 85, world_share: 0, median_age: 43, density: 170, …},
  {country: 'Angola', population_urban: 68, world_share: 0.46, median_age: 16, density: 29, …},
  {country: 'Anguilla', population_urban: 98, world_share: 0, median_age: 38, density: 177, …},
  {country: 'Antigua and Barbuda', population_urban: 28, world_share: 0, median_age: 36, density: 214, …},
  {country: 'Argentina', population_urban: 94, world_share: 0.57, median_age: 32, density: 17, …},
  {country: 'Armenia', population_urban: 67, world_share: 0.03, median_age: 35, density: 98, …},
  ...
]

#2

Hey @sergioSan yes, there is a way to do it, you just need to format your array with a different structure, you need something like this:

var formattedData = [
{
    "group":["Peugeot"],
    "current":{
        "metrics":{
            "Price":8000,
            "Speed": 150
        }
    }
},
{
    "group":["Renault"],
    "current":{
        "metrics":{
            "Price": 9000,
            "Speed": 200
        }
    }
}
];

var data = {
    groups:["Brand Name"],
    metrics:["Price","Speed"],
    data: formattedData
}

Then you can use it in a chart with no providers in this way:


cf.create()
.bars()
.element('your_element_id')
.data(data)
.execute()

#3

Thanks @emoya you really helped me with this, it just work good, it was easy, thanks