Clustered Scatter Chart
Visualizing Distance Traveled by Football Players with ZingChart
In this tutorial, we’ll create a scatter plot using ZingChart to visualize the distance traveled by players in different football games. The chart shows simulated data across multiple games, giving insight into the distances covered minute by minute.
Code Explanation
This code snippet uses JavaScript to generate fake data for eight games, then configures and renders a scatter plot using ZingChart.
- Games Data: Each game is represented as a unique data series.
- Randomized Distances: Distances for each minute in the game are randomized to mimic real-world distribution.
- Chart Configuration: The chart is set up with ZingChart’s scatter plot type, customizable markers, and axes.
Below is the full HTML and JavaScript code for creating this chart.
Code Snippet
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ZingSoft Demo</title> <script src="https://cdn.zingchart.com/zingchart.min.js"></script> <script> // CHART CONFIG // ----------------------------- let chartConfig = { type: 'hbar', theme: 'dark', title: { text: 'Average Temperatures', marginLeft: '20px', }, legend: { align: 'left', backgroundColor: 'none', borderWidth: '0px', item: { cursor: 'hand', fontColor: '#E3E3E5', }, marker: { type: 'circle', borderWidth: '0px', cursor: 'hand', }, offsetY: '25px', verticalAlign: 'top', }, plot: { tooltip: { text: '%data-city<br>High: %data-highs<br>Low: %data-lows', }, }, plotarea: { margin: '120px 50px 60px 85px', }, scaleX: { label: { text: '2020', fontSize: '14px', }, labels: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ], zooming: true, zoomTo: [0, 5], }, scaleY: { format: '%v°F', guide: { lineStyle: 'solid', }, label: { text: 'Temperature', fontSize: '14px', }, }, shapes: [ { type: 'rectangle', id: 'view_all', backgroundColor: '#5e5e5e', borderColor: '#E3E3E5', borderRadius: '3px', borderWidth: '1px', cursor: 'hand', height: '20px', label: { text: 'View All', bold: true, fontColor: '#E3E3E5', fontSize: '12px', }, width: '75px', x: '89%', y: '7%', }, ], series: [ { text: 'New Orleans Average Temps 2020', values: [17, 17, 19, 18, 17, 15, 16, 16, 15, 17, 19, 17], dataCity: 'New Orleans', dataHighs: [62, 65, 72, 78, 85, 89, 91, 91, 87, 80, 72, 64], dataLows: [45, 48, 53, 60, 68, 74, 75, 75, 72, 63, 53, 47], offsetValues: [45, 48, 53, 60, 68, 74, 75, 75, 72, 63, 53, 47], }, { text: 'San Diego Average Temps 2020', values: [16, 14, 13, 11, 10, 9, 10, 9, 9, 12, 15, 17], dataCity: 'San Diego', dataHighs: [65, 65, 66, 67, 69, 71, 75, 76, 76, 73, 69, 65], dataLows: [49, 51, 53, 56, 59, 62, 65, 67, 65, 61, 54, 48], offsetValues: [49, 51, 53, 56, 59, 62, 65, 67, 65, 61, 54, 48], }, { text: 'Denver Average Temps 2020', values: [27, 27, 27, 27, 29, 30, 31, 31, 31, 29, 27, 27], dataCity: 'Denver', dataHighs: [45, 46, 54, 61, 72, 82, 90, 88, 79, 66, 52, 45], dataLows: [18, 19, 27, 34, 43, 52, 59, 57, 48, 37, 25, 18], offsetValues: [18, 19, 27, 34, 43, 52, 59, 57, 48, 37, 25, 18], }, ], scrollX: {}, }; // RENDER CHARTS // ----------------------------- zingchart.render({ id: 'myChart', data: chartConfig, height: '100%', width: '100%', }); // EVENTS // ----------------------------- // store the original zoom level info const origin_zoomin_level = zingchart.exec('myChart', 'getzoom'); // a flag to control the view let switch_view = 'viewall'; zingchart.shape_click = (p) => { if (p.shapeid == 'view_all') { switch (switch_view) { case 'viewall': // change zoom level to viewall zingchart.exec(p.id, 'viewall'); // update the switch button text label // to Previous View zingchart.exec(p.id, 'updateobject', { type: 'shape', data: { id: 'view_all', label: { text: 'Original View', }, width: '110px', } }); // set the flag to previous_view switch_view = 'original_view'; break; case 'original_view': // scale-x and scale-y are array from // origina_zoomin_level object let scale_x = origin_zoomin_level['scale-x']; let scale_y = origin_zoomin_level['scale-y']; // use zoomtovalues to get back to original zoom // level, pass attributes from origin_zoomin_level // object xmin, xmax, ymin, ymax as parameter zingchart.exec(p.id, 'zoomtovalues', { graphid: 0, xmin: scale_x.xmin, xmax: scale_x.xmax, ymin: scale_y.ymin, ymax: scale_y.ymax }); // update the switch button text label // to View All zingchart.exec(p.id, 'updateobject', { type: 'shape', data: { id: 'view_all', label: { text: 'View All', }, width: '75px', } }); // change the flag back to viewall switch_view = 'viewall'; break; } } }; </script> <style> .zc-body { background:#000; } .chart--container { height: 100%; width: 100%; min-height: 530px; } .zc-ref { display: none; } </style> </head> <body class="zc-body"> <div id="myChart" class="chart--container"> <a href="https://www.zingchart.com/" rel="noopener" class="zc-ref">Powered by ZingChart</a> </div> </body> </html>
Running the Code
- Copy the code into an HTML file and open it in your browser.
- You should see a scatter plot with each game represented, showing random distances traveled by players across 90 minutes.
Conclusion
This chart provides a clear and customizable way to represent time-based data, such as player movements, with ZingChart. Happy coding!
NEvolution #nabegh_anane
The above is the detailed content of Clustered Scatter Chart. 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

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











Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.
