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!

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

JavaScript does not require installation because it is already built into modern browsers. You just need a text editor and a browser to get started. 1) In the browser environment, run it by embedding the HTML file through tags. 2) In the Node.js environment, after downloading and installing Node.js, run the JavaScript file through the command line.

How to send task notifications in Quartz In advance When using the Quartz timer to schedule a task, the execution time of the task is set by the cron expression. Now...

How to obtain the parameters of functions on prototype chains in JavaScript In JavaScript programming, understanding and manipulating function parameters on prototype chains is a common and important task...

Analysis of the reason why the dynamic style displacement failure of using Vue.js in the WeChat applet web-view is using Vue.js...


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment