How to create your first chart using FusionCharts.js?
FusionCharts 是一个 JavaScript 库,当您想要创建图表和地图并将其放入您的 Web 中时可以使用它应用。在本教程中,我们将展示如何使用 FusionChart.js 创建两个不同的图表。
在学习如何创建图表之前,第一件重要的事情是了解如何将 FusionCharts 安装到本地计算机上。
安装FusionCharts
我们可以通过多种方式安装 FusionCharts。
使用 CDN
您可以使用下面给出的CDN链接直接访问FusionCharts的文件。
<script src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script>
从 NPM 安装
您可以使用 NPM 将库作为依赖项安装到代码中。使用以下命令安装FusionCharts。
npm install --save fusioncharts
上述命令会将 FusionCharts 保存为项目中的 dev 依赖项。
既然我们知道了如何安装 FusionCharts,那么让我们来探讨一下我们将使用 FusionCharts 创建的几个图表示例。
示例 1
第一个示例是一个简单的条形图,我们将在 FusionCharts 的帮助下创建它,该图按国家/地区描述了亿万富翁的数量。考虑下面所示的代码。
index.html
<html> <head> <title>FusionChart Example - 1</title> <script type="text/javascript"src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script> <script type="text/javascript"src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script> <script type="text/javascript"> const chartData = [{ "label": "United States","value": "735" }, { "label": "Mainland China","value": "539" }, { "label": "India", "value": "166" }, { "label": "Germany", "value": "134" }, { "label": "Russia", "value": "83" }, { "label": "Hong Kong", "value": "67" }, { "label": "Canada", "value": "64" }, { "label": "Brazil", "value": "62" }, { "label": "Italy", "value": "52" }, { "label": "Taiwan", "value": "51" }]; const chartConfig = { type: 'column2d', renderAt: 'chart-container', width: '100%', height: '400', dataFormat: 'json', dataSource: { // Configuration of Chart "chart": { "caption": "Billionares By Country Wise[2022]", "subCaption": "According to Forbes", "xAxisName": "Country", "yAxisName": "Billionares", "theme": "fusion", }, // Actual Chart Data "data": chartData } }; FusionCharts.ready(function() { var fusioncharts = new FusionCharts(chartConfig); fusioncharts.render(); }); </script> </head> <body> <div id="chart-container">FusionCharts!!</div> </body> </html>
如果我们在浏览器中运行上述代码,我们将得到一个绘制为输出的条形图。
说明
在此代码中,我们首先创建了一个 JSON 数据,我们将在创建 FusionChart 对象的实例时将其传递到 chartConfig 的“data”属性中。
除此之外,“chartConfig”对象中还存在一些属性,尤其是“chart”属性,其中我们有不同的子属性,例如 caption、subCaption,这些属性在以下情况下都是必需的:我们正在绘制一个条形图。
示例 2
在上面的示例中,我们使用简单的 JSON 数据创建了一个条形图,并将其呈现给浏览器。在下面的示例中,我们将创建一个更复杂的图表,其中我们将描绘具有多个块的融合图表。考虑下面所示的代码。
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script type="text/javascript"src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script> <script type="text/javascript"src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script> <title>FusionChart - Example 2</title> </head> <body> <div id="chart-container">For Rendering!!</div> <script> FusionCharts.ready(function() { var conversionChart = new FusionCharts({ type: 'bubble', renderAt: 'chart-container', width: '600', height: '450', dataFormat: 'json', dataSource: { "chart": { "theme": "fusion", "caption": "Sales Analysis of Mobile Devices Brands", "subcaption": "Last Quarter", "xAxisMinValue": "0", "xAxisMaxValue": "100", "yAxisMinValue": "0", "yAxisMaxValue": "300000", "xAxisName": "Average Price", "yAxisName": "Units Sold", "numDivlines": "2", "showValues": "1", "showTrendlineLabels": "0", "plotTooltext": "$name : Profit Contribution - $zvalue%", "drawQuadrant": "1", "quadrantLineAlpha": "80", "quadrantLineThickness": "3", "quadrantXVal": "50", "quadrantYVal": "15000", "quadrantLabelTL": "Low Price / High Sale", "quadrantLabelTR": "High Price / High Sale", "quadrantLabelBL": "Low Price / Low Sale", "quadrantLabelBR": "High Price / Low Sale", "yAxisLineThickness": "1", "yAxisLineColor": "#999999", "xAxisLineThickness": "1", "xAxisLineColor": "#999999", "theme": "fusion" }, "categories": [{ "category": [{ "label": "$50", "x": "0" },{ "label": "$100", "x": "20", "showverticalline": "1" },{ "label": "$150", "x": "40", "showverticalline": "1" },{ "label": "$200", "x": "60", "showverticalline": "1" },{ "label": "$250", "x": "80", "showverticalline": "1" }, { "label": "$300", "x": "100", "showverticalline": "1" } ] }], "dataset": [{ "color": "#00aee4", "data": [{ "x": "35", "y": "1500000", "z": "24", "name": "Xiaomi" },{ "x": "80", "y": "1850000", "z": "26", "name": "Samsung" },{ "x": "45", "y": "1945000", "z": "19", "name": "Nokia" },{ "x": "65", "y": "10500", "z": "8", "name": "OnePlus" },{ "x": "100", "y": "905000", "z": "5", "name": "Apple" },{ "x": "32", "y": "2200000", "z": "10", "name": "Asus" },{ "x": "44", "y": "1300000", "z": "9", "name": "Vivo" } ] }], "trendlines": [{ "line": [{ "startValue": "20000", "endValue": "30000", "isTrendZone": "1", "color": "#aaaaaa", "alpha": "14" },{ "startValue": "10000", "endValue": "20000", "isTrendZone": "1", "color": "#aaaaaa", "alpha": "7" } ] }], "vTrendlines": [{ "line": [{ "startValue": "44", "isTrendZone": "0", "color": "#0066cc", "thickness": "1", "dashed": "1", "displayValue": "Gross Avg." }] }] } }); conversionChart.render(); }); </script> </body> </html>
使用“编辑并运行”按钮运行此代码并查看输出。它将显示具有多个象限的图。
说明
在此示例中,我们尝试借助 FusionCharts 描绘多家移动设备公司的销售额。
这里,“数据集”属性包含我们将在图表中显示的实际 JSON 数据,而“类别”包含 X 轴和 Y 轴坐标的数据。
结论
在本教程中,我们使用了几个示例来演示如何利用 FusionCharts 库中的可用功能在 JavaScript 中创建不同的图表。
The above is the detailed content of How to create your first chart using FusionCharts.js?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

The main difference between ES module and CommonJS is the loading method and usage scenario. 1.CommonJS is synchronously loaded, suitable for Node.js server-side environment; 2.ES module is asynchronously loaded, suitable for network environments such as browsers; 3. Syntax, ES module uses import/export and must be located in the top-level scope, while CommonJS uses require/module.exports, which can be called dynamically at runtime; 4.CommonJS is widely used in old versions of Node.js and libraries that rely on it such as Express, while ES modules are suitable for modern front-end frameworks and Node.jsv14; 5. Although it can be mixed, it can easily cause problems.

JavaScript's garbage collection mechanism automatically manages memory through a tag-clearing algorithm to reduce the risk of memory leakage. The engine traverses and marks the active object from the root object, and unmarked is treated as garbage and cleared. For example, when the object is no longer referenced (such as setting the variable to null), it will be released in the next round of recycling. Common causes of memory leaks include: ① Uncleared timers or event listeners; ② References to external variables in closures; ③ Global variables continue to hold a large amount of data. The V8 engine optimizes recycling efficiency through strategies such as generational recycling, incremental marking, parallel/concurrent recycling, and reduces the main thread blocking time. During development, unnecessary global references should be avoided and object associations should be promptly decorated to improve performance and stability.

There are three common ways to initiate HTTP requests in Node.js: use built-in modules, axios, and node-fetch. 1. Use the built-in http/https module without dependencies, which is suitable for basic scenarios, but requires manual processing of data stitching and error monitoring, such as using https.get() to obtain data or send POST requests through .write(); 2.axios is a third-party library based on Promise. It has concise syntax and powerful functions, supports async/await, automatic JSON conversion, interceptor, etc. It is recommended to simplify asynchronous request operations; 3.node-fetch provides a style similar to browser fetch, based on Promise and simple syntax

The difference between var, let and const is scope, promotion and repeated declarations. 1.var is the function scope, with variable promotion, allowing repeated declarations; 2.let is the block-level scope, with temporary dead zones, and repeated declarations are not allowed; 3.const is also the block-level scope, and must be assigned immediately, and cannot be reassigned, but the internal value of the reference type can be modified. Use const first, use let when changing variables, and avoid using var.

The main reasons for slow operation of DOM are the high cost of rearrangement and redrawing and low access efficiency. Optimization methods include: 1. Reduce the number of accesses and cache read values; 2. Batch read and write operations; 3. Merge and modify, use document fragments or hidden elements; 4. Avoid layout jitter and centrally handle read and write; 5. Use framework or requestAnimationFrame asynchronous update.
