Pushing the Boundaries of JavaScript Chart Dashboard Performance
Tags: javascript, chart, webdev, programming
Published: 2024-03-13 15:19:09

<!-- wp:paragraph -->
<p>At SciChart.js we've blogged several times on the incredible speed and performance of our <a href="https://scichart.com/javascript-charts" target="_blank" rel="noreferrer noopener" data-type="URL" data-id="https://scichart.com/javascript-charts">JavaScript Chart library</a>. For example, this post from last year showcases SciChat.js drawing <a href="https://www.scichart.com/blog/javascript-chart-performance-plotting-10-million-datapoints-in-under-25ms/" target="_blank" rel="noreferrer noopener" data-type="URL" data-id="https://www.scichart.com/blog/javascript-chart-performance-plotting-10-million-datapoints-in-under-25ms/">10 million data-points in under 25 milliseconds</a>. Another blog demonstrates <a href="https://www.scichart.com/blog/javascript-candlestick-charts-plotting-years-1-minute-data/" target="_blank" rel="noreferrer noopener" data-type="URL" data-id="https://www.scichart.com/blog/javascript-candlestick-charts-plotting-years-1-minute-data/">how SciChart.js transforms trading performance</a>: as we have the only JS chart framework able to load the entire history of Bitcoin in a 1-minute candlestick chart in javascript.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>However, some of our users require more than just a fast single chart. Here is a challenging requirement which was given to us by a customer of SciChart.js:</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Customer Requirement - JS Dashboards</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><em>Customer A wanted a grid of up to 100 charts, <em>each chart could have tens of thousands of datapoints. They needed to be interactive</em> with synchronised x axes, which means that when any chart is zoomed/panned, every chart has to redraw.  Text labels had to be visible for all charts and dynamically update as the chart is zoomed.</em></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A dashboard with 100 charts look like this:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":33565,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img class="wp-image-33565" src="https://www.scichart.com/wp-content/uploads/2022/06/dashboard-javascript-chart.png" alt="" /></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The stats / requirements are:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul>
<li>100 javascript charts in a single browser window</li>
<li>Each chart with 60,000+ datapoints (total 6 million points)</li>
<li>200 axis each with 5 labels per axis</li>
<li>Total of 1,000 text labels and 6 million datapoints</li>
<li>This had to render at interactive speeds (30 FPS or better)</li>
</ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Our first attempt</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Our first attempt at this used our built-in API to <a href="https://www.scichart.com/documentation/js/current/Tutorial%2009%20-%20Linking%20Multiple%20Charts.html" target="_blank" rel="noreferrer noopener" data-type="URL" data-id="https://www.scichart.com/documentation/js/current/Tutorial%2009%20-%20Linking%20Multiple%20Charts.html">synchronise multiple JavaScript charts</a>. This worked, but the performance wasn't good enough. Only 1-2 FPS for 100 charts. We had to improve.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Improving text rendering speed in JavaScript</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>A major bottleneck we identified was the text rendering. With 1,000s of text labels on screen for this example the time just to draw the text was significant. To solve this, <strong>we implemented a novel native text rendering algorithm within our WebGL/WebAssembly graphics engine</strong>.  This has been built into SciChart.js and includes full font support, including for shaped fonts like Arabic, Korean, Japanese and right to left text. This improved performance by a factor of 4 for the 100 chart dashboard scenario.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Unifying Rendering of multiple charts</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The next bottleneck is that by default, SciChart.js uses WebGL context sharing to get around the limit of 16 WebGL contexts per browser page. This has some extra overhead associated with drawing which is noticeable as the number of charts adds up. You can turn this off, opting for one WebGL context per chart (<a href="https://www.scichart.com/documentation/js/current/SciChartSurface.create%20and%20createSingle.html" target="_blank" rel="noreferrer noopener" data-type="URL" data-id="https://www.scichart.com/documentation/js/current/SciChartSurface.create%20and%20createSingle.html">see documentation here</a>), but then you'll hit a hard limit of 16 charts on screen.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So, what if we combined the best of both worlds?</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Our solution was to build an entirely new API called the SubCharts API which allows you to add multiple SciChartSurfaces to an existing chart surface. Our rendering engine then batches draw calls for all these charts into one. This technique doubled performance again, so we are now up to 8-10 times faster than before. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Final results</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Below are the final results in table and chart form. With these enhancements, SciChart.js is able to render over 100 charts in a 10x10 dashboard, each with tens of thousands of data-points and refresh or update at 30 FPS. Even 192 charts is possible using these new techniques, allowing massive dashboards with hundreds of charts in a browser.</p>
<!-- /wp:paragraph -->

<!-- wp:table {"hasFixedLayout":true,"className":"is-style-stripes"} -->
<figure class="wp-block-table is-style-stripes">
<table class="has-fixed-layout">
<thead>
<tr>
<th># Charts</th>
<th>v2.x FPS</th>
<th>Native Text FPS</th>
<th>Subcharts FPS</th>
<th>Speed up (%)</th>
</tr>
</thead>
<tbody>
<tr>
<td>4 Charts</td>
<td>58.9</td>
<td>60</td>
<td>60</td>
<td>+2%</td>
</tr>
<tr>
<td>8 Charts</td>
<td>49.9</td>
<td>59.9</td>
<td>60</td>
<td>+20%</td>
</tr>
<tr>
<td>16 Charts</td>
<td>25.9</td>
<td>59.9</td>
<td>60</td>
<td>+131%</td>
</tr>
<tr>
<td>32 Charts</td>
<td>13.4</td>
<td>47.4</td>
<td>60</td>
<td>+347%</td>
</tr>
<tr>
<td>64 Charts</td>
<td>6.6</td>
<td>24.5</td>
<td>46.6</td>
<td>+606%</td>
</tr>
<tr>
<td>128 Charts</td>
<td>3.4</td>
<td>13.0</td>
<td>28.9</td>
<td>+789%</td>
</tr>
<tr>
<td>192 Charts</td>
<td>-</td>
<td>8.3</td>
<td>17</td>
<td>INF</td>
</tr>
</tbody>
</table>
<figcaption>Speed improvements in SciChart.js for multi-chart scenario (dashboards) using our new APIs!</figcaption>
</figure>
<!-- /wp:table -->

<!-- wp:paragraph -->
<p>Here are the performance results in chart form. You can see that with these improvements SciChart.js can greatly improve the overall responsiveness and interactivity of dashboards with hundreds of JavaScript charts.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":33567,"width":550,"height":407,"sizeSlug":"full","linkDestination":"none"} -->
<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img class="wp-image-33567" src="https://www.scichart.com/wp-content/uploads/2022/06/js-dashboard-performance.png" alt="" width="550" height="407" />
<figcaption>Speed improvements in SciChart.js for multi-chart scenario using our new APIs</figcaption>
</figure>
</div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>When will these improvements be available?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The SubCharts API which allows you to place charts in charts will be available as part of the SciChart.js v2.3 release, due later this year. This release will also include native text enhancements for better text label drawing performance and text labels on datapoints.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="about-scichart-high-performance-realtime-charts"><strong><em>About SciChart: High Performance Realtime Charts</em></strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><em>SciChart provides high performance real–time chart components on the <a href="https://www.scichart.com/wpf-chart-features/">WPF</a> (Windows), iOS, Android and <a href="https://www.scichart.com/javascript-chart-features/">JavaScript</a> platforms. Our software is used by companies that require the fastest possible 2D &amp; 3D charts such as <a href="/realtime-telemetry-datavisualisation-formulaone-motorsport/">Formula One</a>, <a href="/data-visualization-for-the-epilepsy-research-kit-for-kids/">research </a>&amp; <a href="/powering-research-development-innovation-worldwide/">scientific innovation</a>, <a href="/android-app-to-view-long-term-ecg-signals/">medical companies</a> and more. So, when they ask us to push the boundaries of performance even further, we spare no expense!</em></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><em>If you have a question about what SciChart’s WebGL / WebAssembly Charts can offer you, or if you would like to get a quote, please <a href="https://www.scichart.com/contact-us/">contact us</a>. Our friendly, helpful team will be glad to help!</em></p>
<!-- /wp:buttons -->
<blockquote>
<h2>Start using SciChart.js Today</h2>
SciChart.js is now available with a <a href="https://www.scichart.com/getting-started/scichart-javascript"><strong>FREE community edition</strong></a> (no trial, sign-up or credit card required) where you can try out the library commercially or use it in a non-commercial application. If you have a question, or would like to give feedback, contact us.<br /><br />
<p style="text-align: center;"><a class="button" href="https://scichart.com/contact-us">CONTACT US</a><a class="button" href="https://www.scichart.com/getting-started/scichart-javascript/">GET SCICHART.JS FREE</a></p>
</blockquote>