


[JavaScript] Detailed explanation of displaying multiple statistical charts and graphics on the same page
Recently, I received a development task, which required me to make statistics on the feedback answers filled in by customers in the "After-sales Service Customer Satisfaction Questionnaire".
An example of a question is:
When was the last time you purchased our product?
# Are the service staff friendly and conscientious?
#How do you overall feel about the after-sales service provided by our company?
. . .
#The function I want to implement is to produce a report that displays the total number of occurrences of each answer for each question on the same page.
I achieved a simple effect, as shown below:
Of course, all six icons are used It is the same test data, which mainly solves the layout problem of multiple charts appearing on the same page.
Please use the link below to test the effect. You can use Chrome developer tools to view the implementation of 093_chart.html.
The effect of opening on mobile phone.
Let’s briefly review the code:
Each of the two ps contains 6 canvases. The first p is responsible for displaying the results of the problem with 6 pie charts, and the 6 canvases in the second p display the bar chart. I used the display:inline attribute marked !important on each canvas to force the statistical charts located in the canvas node to be displayed from left to right, instead of the default of wrapping every time one is displayed.
function loaded(){ var totalWidth = getBodyNode().clientWidth; console.log("width in load: " + totalWidth); var aCharts = document.getElementsByTagName("canvas"); for( var i = 0; i < aCharts.length; i++){ aCharts[i].width = totalWidth / 6.5; } var option = { type: "pie", xAxisData: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], yAxisData: [12, 19, 3, 5, 2, 3], yAxisLabel: "Number of Votes" }; for( var i = 1; i <= 6; i++ ){ createChartOnCanvas("myChart" + i, option); } option.type = "bar"; for( var i = 1; i <= 6; i++ ){ createChartOnCanvas("barChart" + i, option); } }
Line 41 obtains the total width of the current window through the clientWidth property of the body node, and then divides it by 6.5. The quotient is the width of each statistical chart. The reason why we divide by 6.5 instead of 6 is to leave some space between the statistical charts in each row.
The type of statistical chart, the data and labels of X and Y coordinates are passed into the function createChartOnCanvas through the option object.
Related recommendations:
How does Baidu Map JavaScript API display multiple maps on the same page
Display multiple iChart reports on one page
The above is the detailed content of [JavaScript] Detailed explanation of displaying multiple statistical charts and graphics on the same page. For more information, please follow other related articles on the PHP Chinese website!

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

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



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript
