您好,登錄后才能下訂單哦!
使用HighCharts怎么繪制一個(gè)2D圓環(huán)圖?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
1、實(shí)例代碼:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>HighCharts 2D圓環(huán)圖</title> <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="js/highcharts.js"></script> <script type="text/javascript"> $(function(){ var colors = Highcharts.getOptions().colors, categories = ['花', '樹', '魚', '鳥', '鯨'], name = 'Browser brands', data = [{ y: 55.11, color: colors[0], drilldown: { name: '花的種類', categories: ['梅花', '桃花', '梨花', '櫻花'], data: [13.6, 7.35, 33.06, 2.81], color: colors[0] } }, { y: 21.63, color: colors[1], drilldown: { name: '樹的種類', categories: ['樟樹', '桉樹', '茶樹', '桃樹', '梨樹'], data: [15.20, 3.83, 18.58, 13.12, 45.43], color: colors[1] } }, { y: 11.94, color: colors[2], drilldown: { name: '魚的種類', categories: ['鯽魚', '鰱魚', '草魚', '青魚', '鰷魚','鳙魚', '鰣魚'], data: [41.12, 10.19, 11.12, 14.36, 21.32, 9.91, 17.50], color: colors[2] } }, { y: 7.15, color: colors[3], drilldown: { name: '鳥的種類', categories: ['松雞', '卷尾', '鷦鷯', '巖鷚', '山鶉','畫眉', '金雞'], data: [14.55, 19.42, 16.23, 16.21, 18.20, 23.19, 10.14], color: colors[3] } }, { y: 2.14, color: colors[4], drilldown: { name: '鯨的種類', categories: ['須鯨', '藍(lán)鯨', '虎鯨'], data: [ 24.12, 18.37, 32.65], color: colors[4] } }]; // 構(gòu)建物種數(shù)據(jù) var speciesData = []; var speData = []; for (var i = 0; i < data.length; i++) { // 添加物種數(shù)據(jù) speciesData.push({ name: categories[i], y: data[i].y, color: data[i].color }); for (var j = 0; j < data[i].drilldown.data.length; j++) { var brightness = 0.4 - (j / data[i].drilldown.data.length) / 5 ; speData.push({ name: data[i].drilldown.categories[j], y: data[i].drilldown.data[j], color: Highcharts.Color(data[i].color).brighten(brightness).get() }); } } // 創(chuàng)建圓環(huán)圖 $('#donutChart').highcharts({ chart: { type: 'pie' }, title: { text: '物種數(shù)量及其比例' }, yAxis: { title: { text: '比例' } }, plotOptions: { pie: { shadow: true, center: ['50%', '50%'] } }, tooltip: { valueSuffix: '%' }, series: [{ name: '物種', data: speciesData, size: '70%', dataLabels: { formatter: function() { return this.y > 5 ? this.point.name : null; }, color: 'white', distance: -30 } }, { name: '數(shù)量', data: speData, size: '80%', innerSize: '80%', dataLabels: { formatter: function() { return this.y > 1 ? '<b>'+ this.point.name +':</b> '+ this.y +'%' : null; } } }] }); }); </script> </head> <body> <div id="donutChart" ></div> </body> </html>
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。