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
<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> <div id="myChart" class="chart--container"> <a href="https://www.zingchart.com/" rel="noopener" class="zc-ref">Powered by ZingChart</a> </div>
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!

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Enhance Your Code Presentation: 10 Syntax Highlighters for Developers Sharing code snippets on your website or blog is a common practice for developers. Choosing the right syntax highlighter can significantly improve readability and visual appeal. T

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

This article presents a curated selection of over 10 tutorials on JavaScript and jQuery Model-View-Controller (MVC) frameworks, perfect for boosting your web development skills in the new year. These tutorials cover a range of topics, from foundatio

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was


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

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
