翻譯|使用教程|編輯:吳園園|2019-11-15 13:28:11.593|閱讀 321 次
概述:FusionCharts Suite XT包含高級(jí)功能,可讓您向圖表添加更多上下文并簡化數(shù)據(jù)可視化。這些功能包括圖表更新,百分比計(jì)算和事件。本文重點(diǎn)介紹如何計(jì)算數(shù)據(jù)圖相對于所有數(shù)據(jù)圖的百分比。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
FusionCharts Suite XT是全面的跨平臺(tái)、跨瀏覽器JavaScript圖表套包,其中包括FusionCharts XT、PowerCharts XT 、FusionWidgets XT 、FusionMaps XT。支持 ASP、 ASP.NET、 PHP、 JSP、 ColdFusion、 Ruby on Rails、 JavaScript、甚至簡單的HTML頁面。它是你值得信賴的JavaScript圖表解決方案,目前在全球有45萬用戶選擇Fusioncharts來制作專業(yè)的JavaScript圖表。
JavaScript圖表工具,為什么選擇FusionCharts?點(diǎn)擊了解!
點(diǎn)擊下載FusionCharts Suite XT最新試用版
百分比計(jì)算
事件是使您可以使用JavaScript響應(yīng)圖表的任何交互/更新來執(zhí)行特定操作(例如,將數(shù)據(jù)發(fā)送到服務(wù)器等)的信號(hào)。FusionCharts Suite XT包含高級(jí)功能,可讓您向圖表添加更多上下文并簡化數(shù)據(jù)可視化。這些功能包括圖表更新,百分比計(jì)算和事件。
本文重點(diǎn)介紹如何計(jì)算數(shù)據(jù)圖相對于所有數(shù)據(jù)圖的百分比。
配置為計(jì)算百分比的圖表如下所示:
上面示例的完整代碼如下:
import FusionCharts from 'fusioncharts';import Charts from 'fusioncharts/fusioncharts.charts';import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';// Add the chart and theme as dependencyFusionCharts.addDep(Charts);FusionCharts.addDep(FusionTheme);// Create an Instance with chart optionsvar chartInstance = new FusionCharts({ type: 'column2d', height: '400', width: '700', dataFormat: 'json', renderAt: 'chart-container', dataSource: { "chart": { "caption": "Countries With Most Oil Reserves [2017-18]", "subCaption": "In MMbbl = One Million barrels", "xAxisName": "Country", "yAxisName": "Reserves (MMbbl)", "numberSuffix": "K", "theme": "fusion" }, "data": [{ "label": "Venezuela", "value": "290" }, { "label": "Saudi", "value": "260" }, { "label": "Canada", "value": "180" }, { "label": "Iran", "value": "140" }, { "label": "Russia", "value": "115" }, { "label": "UAE", "value": "100" }, { "label": "US", "value": "30" }, { "label": "China", "value": "30" }], }, "events": { "beforeRender": function(e, d) { var message = "Hover on the plot to see the percentage along with the label"; var customDiv = document.createElement('p'); customDiv.innerText = message; customDiv.style.padding = "10px"; customDiv.style.background = "rgb(245, 242, 240)"; customDiv.style.textAlign = "center"; e.data.container.appendChild(customDiv); var total = 0; e.sender.args.dataSource.data.forEach(function(dataObj) { total += parseFloat(dataObj.value); }); e.sender.addEventListener("dataplotrollover", function(rollEvent, rollData) { var value = (rollData.value / total * 100).toFixed(2); customDiv.innerHTML = '<b>' + rollData.categoryLabel + '</b> is <b>' + value + '%</b> of top 8 oil reserve countries'; }); e.sender.addEventListener("dataplotrollout", function(rollEvent, rollData) { customDiv.innerText = message; }); } }});// RenderchartInstance.render();
上圖通過以下步驟呈現(xiàn):
1、使用包括必要的庫和組件import。例如fusioncharts library等
2、將圖表和主題添加為依賴項(xiàng)。
3、將圖表配置存儲(chǔ)在JSON對象中。在JSON對象中:
將圖表類型設(shè)置為column2d。
設(shè)置圖表的寬度和高度(以像素為單位)。
將設(shè)置dataFormat為JSON。
將json數(shù)據(jù)嵌入為的值dataSource。
4、設(shè)置message隨圖表呈現(xiàn)一起顯示的。
5、在上面的示例中:
dataplotrollover 事件在頁面上顯示了懸停圖的百分比。
dataplotrollout 事件重置默認(rèn)消息。
6、addEventListener 用于更新上面列出的事件。
====================================================
想了解更多關(guān)于FusionCharts Suite XT資源,請點(diǎn)擊此處
想要了解或者購買FusionCharts Suite XT正版授權(quán)的朋友歡迎
關(guān)注下方微信公眾號(hào),及時(shí)獲取產(chǎn)品最新消息和最新資訊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: