第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Highcarts 中使用數(shù)組?

如何在 Highcarts 中使用數(shù)組?

HUX布斯 2021-11-18 20:40:01
我的代碼中有兩個(gè)數(shù)組,我想使用 Highcharts 在餅圖上繪制一些數(shù)據(jù)。一個(gè)數(shù)組包含該數(shù)據(jù)的標(biāo)簽,另一個(gè)數(shù)組包含數(shù)據(jù)。這是我嘗試過的:arr1 = [10, 39, 30]arr2 = ['one', 'two', 'three']Highcharts.chart('container-2', {  chart: {    margin: [0, 0, 0, 0],    spacingTop: 0,    spacingBottom: 0,    spacingLeft: 0,    spacingRight: 0,    plotBackgroundColor: null,    plotBorderWidth: null,    plotShadow: false,    type: 'pie'  },  title: {    text: 'Example'  },  tooltip: {    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'  },  plotOptions: {    pie: {      size: '50%',      allowPointSelect: true,      cursor: 'pointer',      dataLabels: {        enabled: true,        format: '<b>{point.name}</b>: {point.percentage:.1f} %'      }    }  },  series: [{    name: 'Balances',    colorByPoint: true,    data: {        y: arr1,        name: arr2,    }  }]});不幸的是,這會(huì)生成一個(gè)沒有任何數(shù)據(jù)的圖表。有人可以幫我找出我做錯(cuò)了什么嗎?
查看完整描述

2 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

arrays使用y和name作為屬性格式化來自對(duì)象數(shù)組中的標(biāo)簽和數(shù)據(jù)的數(shù)據(jù)。


const arr1 = [10, 39, 30];

const arr2 = ["one", "two", "three"];


const pieData = arr1.map((cur, index) => {

  return { name: arr2[index], y: cur };

});


console.info("PIEDATA::", pieData);


然后將此格式化數(shù)據(jù)傳遞給系列數(shù)據(jù):


//notice data should be an array of objects for those pie plotting values

    series: [{

        name: 'Balances',

        colorByPoint: true,

        data:pieData

      }]


查看完整回答
反對(duì) 回復(fù) 2021-11-18
?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

y并且name應(yīng)該是單一值。您必須直接將兩個(gè)數(shù)組轉(zhuǎn)換為一個(gè)對(duì)象:


let data = {}

for(let i=0;i<arr1.length;i++){

    data[arr2[i]] = data[arr1[i]];

}

然后在圖表選項(xiàng)中:


Highcharts.chart('container-2', {

    ...

    series: [{

        name: 'Balances',

        colorByPoint: true,

        data: data

    }]

});


查看完整回答
反對(duì) 回復(fù) 2021-11-18
  • 2 回答
  • 0 關(guān)注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)