Tengo una salida de mi json como esta:
0: {api: 'Cars', method: 'GET', total: 3} 1: {api: 'Cars', method: 'POST', total: 4} 2: {api: 'Trucks', method: 'POST', total: 6} 3: {api: 'Boats', method: 'GET', total: 6}y lo que quiero volver a crear matriz para poblar series en Highchart.js con el tipo: burbuja empaquetada
[ Cars: [ {name: "GET", value: 3}, {name: "PUT", value: 0}, {name: "POST", value: 4}, {name: "DELETE", value: 0} ], Trucks: [ {name: "GET", value: 0}, {name: "PUT", value: 0}, {name: "POST", value: 6}, {name: "DELETE", value: 0} ], Boats: [ {name: "GET", value: 6}, {name: "PUT", value: 0}, {name: "POST", value: 0}, {name: "DELETE", value: 0} ] ]El formato sugerido no es correcto para la serie de packedbubble . Consulte la referencia de la API: https://api.highcharts.com/highcharts/series.packedbubble.data
Si desea convertir sus datos json, puede hacerlo de la siguiente manera:
let data = [{api: 'Cars', method: 'GET', total: 3}, {api: 'Cars', method: 'POST', total: 4}, {api: 'Trucks', method: 'POST', total: 6}, {api: 'Boats', method: 'GET', total: 6}]; let cars = [], trucks = [], boats = []; data.forEach(obj => { if (obj.api === "Cars") { cars.push({ name: obj.method, value: obj.total }) } else if (obj.api === "Trucks") { trucks.push({ name: obj.method, value: obj.total }) } else if (obj.api === "Boats") { boats.push({ name: obj.method, value: obj.total }) } })...
series: [{ name: 'Cars', data: cars }, { name: 'Trucks', data: trucks }, { name: 'Boats', data: boats }]Demostración: https://jsfiddle.net/BlackLabel/juxg964q/