DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • Decoding the Confusion Matrix: A Comprehensive Guide to Classification Model Evaluation
  • How To Create a Resource Chart in JavaScript
  • Precision at Scale: Unveiling the Secrets of Quality Engineering in Data Engineering
  • A Guide to Data Labeling and Annotating: Importance, Types, and Best Practices

Trending

  • Real-Time Anomaly Detection
  • Elevating React Development: Unleashing the Power of ChatGPT for React Developers
  • Transitioning From Point-To-Point to an API-Centric Approach
  • Java 11 to 21: A Visual Guide for Seamless Migration
  1. DZone
  2. Data Engineering
  3. Data
  4. Create a Millisecond-Precision Time Ticks Chart with NodeJS

Create a Millisecond-Precision Time Ticks Chart with NodeJS

You'll create an interactive and real-time time ticks chart with NodeJS and LightningChart JS. This chart features an ultra-high precision zoom level up to milliseconds.

Omar Urbano user avatar by
Omar Urbano
·
Aug. 09, 22 · Tutorial
Like (2)
Save
Tweet
Share
5.2K Views

Join the DZone community and get the full member experience.

Join For Free

Hello!

Omar from LightningChart here. As my first article for DZone, I wanted to experiment with how to create different charts available from the lcjs library.

This time, I'll walk you through how to create a time ticks chart using NodeJS and the lcjs library.   

JavaScript Time Ticks Chart

JS Time Ticks Chart

There are several options for placing and formatting automatic axis ticks within a chart. In this case, we're using TimeTickStrategy, as featured in the LightningChart JS library. 

This feature has been designed for depicting milliseconds of timestamp data with an extremely high resolution, flexibility, and performance.

The effective range of TimeTickStrategy starts from a maximum of 100 hours all the way down to rendering at a level of individual milliseconds.

So, in a real-world use case scenario, this chart is specially designed for industries that require visualizing data at very low zoom levels—for instance, visualizing data points of an 8-hour, 1-hour, 1-minute, 1-second, or even 1-millisecond interval.

For this entire range, the tick labels are formatted dynamically, showing the currently relevant precision with all the required accuracy.

Some industries that benefit from this would be trading, real-time monitoring, research, engineering, and even audio and vibration analysis.

You can read more about the chart here.

With that being said, let's set up our project template.

Setting Up Our Template

  1. To follow the article, you'd ideally download the project template. The template is a RAR file and you can download the Time Ticks Chart project template here.
  2. Once downloaded, please open up the folder in Visual Studio Code. Then, you'll see a file tree like this:Project-Time-Ticks-Chart-file-tree
  3. Now, open a new terminal.
  4. And, as usual in a NodeJS project, we will have to run our NPM Install command.

This would be everything for our initial setup.

Let’s code.

CHART.ts

Inside this file, we will have all the logic needed to create our chart, configure animations, and format the data.

1. Declare the constant lcjs that will refer to setting up the @arction/lcjs library.

2. Extract required classes from lcjs.

JavaScript
 
// Import LightningChartJS
const lcjs = require('@arction/lcjs')

// Extract required parts from LightningChartJS.
const {
    lightningChart,
    AxisTickStrategies,
    Themes
} = lcjs

3. Next, we'll start creating the chart object.

JavaScript
 
const chart = lightningChart()
    .ChartXY({
        theme: Themes.cyberSpace,
    })
    .setTitle('TimeTickStrategy example')
    .setPadding({ right: 40 })
    .setMouseInteractionsWhileScrolling(true)

So, here's a quick explanation of what the properties do:

  • setMouseInteractionWhileScrolling. This determines if the mouse and cursor interactions should be disabled during scrolling animations for the chart's series.

Parameters

  • State: Boolean. Set to True if the mouse and the cursor interactions should be disabled during the scrolling animations, false if otherwise.
  • Returns this: The chart itself for a fluent interface.
  • Theme: it refers to the collection of default implementations that can be accessed by Themes. The Color theme of the components must be specified when it is created, and can't be changed afterward (without destroying and having to recreate the component). You can read more about the themes here.

4. createProgressiveTraceGenerator: 

This property creates a new Sampled data generator with default values. This means that the generator will sample the given input data array at a specific frequency. See the code below:

JavaScript
 
const {
    createProgressiveTraceGenerator
} = require('@arction/xydata')

5. getDefaultAxisY: 

This property will retrieve the Y-axis.
setScrollStrategy: Specify ScrollStrategy of the Axis. This decides where the Axis scrolls based on the current view and series boundaries. 

6. getDefaultAxisX: This property will retrieve the X-axis.

setTickStrategy: The TickStrategy defines the positioning and formatting logic of the Axis ticks as well as the style of created ticks. You can read more about the setTickStrategy here.

JavaScript
 
const axisX = chart
    .getDefaultAxisX()
    // Enable TimeTickStrategy for X Axis.
    .setTickStrategy(AxisTickStrategies.Time)

const axisY = chart.getDefaultAxisY()


7. addLineSeries: This is a method for adding a new LineSeries to the chart. Briefly, what a line series does is visualize a list of given coordinates (X and Y points) with a continuous stroke.

It's worth mentioning that the LineSeries is fully optimized for visualizing a massive amount of data, seizing the GPU acceleration capability of the lcjs library.

However, the final amount of data rendered will depend on the LineSeries type. LightningChart JS supports static, refreshing, and appending line charts.

For instance, when testing the static line charts for visualizing 10 million data points, the loading speed is only 330 ms.

On the other hand, a refreshing line chart processes 1 million data points at 10 FPS using only 57.6% of the CPU resources. And for appending line charts, 1 million data points per second are appended using only 23.7% of CPU resources, at a rounded 60 FPS.

Therefore, the LineSeries performance will depend on your application requirements, but the component is mainly a performance-oriented component. 

If you want to know more about the latest of LineSeries performance, visit the LineSeries performance comparison.

JavaScript
 
const series = chart.addLineSeries({
    dataPattern: {
        pattern: 'ProgressiveX',
    },
})

8. addLegendBox: this property adds a box to the chart. The box has the capability of hiding and showing the data series. 

addLegendBox property

JavaScript
 
const legend = chart.addLegendBox().add(chart)
    // Dispose example UI elements automatically if they take too much space. This is to avoid bad UI on mobile / etc. devices.
    .setAutoDispose({
        type: 'max-width',
        maxWidth: 0.30,
    })

9. numberOfPoints: This property sets the number of points to be displayed in the charts. If you decide to use smaller values, the chart will look simplified.

I'll set my example to: const numberOfPoints = 1 * 10

numberOfPoints property

JavaScript
 
// Generate ~8 hours of data for line series.
const numberOfPoints = 1 * 10
// TimeTickStrategy interprets values as milliseconds (UNIX timestamp).
const xInterval = 80 * 60 * 60 * 1000
createProgressiveTraceGenerator()
    .setNumberOfPoints(numberOfPoints)
    .generate()
    .toPromise()
    .then((data) => {
        data = data.map((p) => ({
            x: (p.x * xInterval) / numberOfPoints,
            y: p.y,
        }))
        series.add(data)
    })

NPM Start

Finally, you'll just have to run the npm start command to visualize the time ticks chart in a local server:

Open-new-terminal

Run "npm start" and you'll get access to your local server:

project-running-on-localhost

Final Words

The TimeTicksStrategy is a powerful property that allows you to render data up to a millisecond's precision. This is especially useful when working with high-frequency data, or when you need to display very precise timing information. 

This makes the TimeTicksStrategy an ideal feature for applications that require full precision rendering when visualizing millions of data points in real time, such as financial or scientific applications. 

With the TimeTicksStrategy property, you can ensure that your data is rendered accurately and efficiently.

So, this is definitely a useful feature for those developers who need to track data over very short periods of time, such as when monitoring computer processes or network activity. 

If you need this level of detail in your charts, then the line series chart is definitely worth considering.

Thanks!

Chart Data (computing) Label Precision (computer science)

Opinions expressed by DZone contributors are their own.

Related

  • Decoding the Confusion Matrix: A Comprehensive Guide to Classification Model Evaluation
  • How To Create a Resource Chart in JavaScript
  • Precision at Scale: Unveiling the Secrets of Quality Engineering in Data Engineering
  • A Guide to Data Labeling and Annotating: Importance, Types, and Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: