How can I modify the display value in a series using Highcharts?

Hey there, I'm relatively new to stackoverflow, django, and highcharts so please bear with me if I make any mistakes.

Currently, I'm working on displaying time and dates in highcharts and came across a small issue. Everything looks fine on the chart like this:

https://i.sstatic.net/6hALh.png

However, when I hover over a point on the chart, it displays a different value. It looks something like this: https://i.sstatic.net/WUr2p.png

I would like the focus to display as HH:MM:SS instead of showing the total amount of microseconds. What changes do I need to make for this to happen?

Here is the code snippet for the chart:

    <script>
                                $(function () {
                                $('#container').highcharts({
                                    chart:
                                    {
                                        type: 'line'
                                    },
                                    title:
                                    {
                                        text: 'Time worked by {{user_to_show}}'
                                    },
                                    xAxis:
                                    {
                                        categories: {{dates|safe}}
                                    },
                                    yAxis:
                                    [{
                                        title:
                                        {
                                            text: ''
                                        },
                                        gridLineWidth: 1,
                                        type: 'datetime', //y-axis will be in milliseconds
                                        dateTimeLabelFormats:
                                        { //force all formats to be hour:minute:second
                                                second: '%H:%M:%S',
                                                minute: '%H:%M:%S',
                                                hour: '%H:%M:%S',
                                                day: '%H:%M:%S',
                                                week: '%H:%M:%S',
                                                month: '%H:%M:%S',
                                                year: '%H:%M:%S'
                                        },
                                        opposite: true
                                    }],
                                    plotOptions:
                                    {
                                        series:
                                        {
                                            dataLabels:
                                            {
                                                enabled: true,
                                                formatter: function()
                                                {
                                                    if( this.series.index == 0 )
                                                    {
                                                        return secondsTimeSpanToHMS(this.y/1000) ;
                                                    }
                                                    else
                                                    {
                                                        return this.y;
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    series:
                                    [{
                                        name: 'Time',
                                        yAxis: 0,
                                        data: {{time|safe}}
                                    }]
                                });
                            });

                        function secondsTimeSpanToHMS(s) {
                            var h = Math.floor(s / 3600); //Get whole hours
                            s -= h * 3600;
                            var m = Math.floor(s / 60); //Get remaining minutes
                            s -= m * 60;
                            return h + ":" + (m < 10 ? '0' + m : m) + ":" + (s < 10 ? '0' + s : s); //zero padding on minutes and seconds
                        }
 </script>

If you require more code, data, or information, feel free to let me know. Appreciate any help in advance!

Answer №1

After some tinkering, I managed to solve my issue by incorporating the following code snippet:

tooltip:
                                {
                                        formatter: function ()
                                        {
                                            var text = this.x + ': ' + secondsTimeSpanToHMS(this.y/1000);
                                            return text;
                                        }
                                },

This adjustment resulted in the desired outcome: https://i.sstatic.net/vpxyJ.png

(I would mark this post as solved, but stackoverflow has a 2-day waiting period for that)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with transmitting a JSON array to a Node.js server using AJAX

When sending data via AJAX to my nodejs server, I use the following JavaScript on the client side: function login(){ var array=[]; var jsonData={}; jsonData.user=$('#user').val(); jsonData.pass=$('#pass').val(); arr ...

What is the best way to update a single model instance that has been retrieved using the get() method on Django ORM

Currently in my function, I utilize Models.object.get(), resulting in the return of either 0 or 1 model objects: If it returns 0, I handle this by creating a new model instance within the except DoesNotExist clause of the function. On the other hand, if a ...

Utilizing jQuery TableSorter Scroller: How to Achieve Scrolling with Keydown Focus

Apologies for any language barriers. I am currently utilizing tablesorter 2.0 along with scroller functionality. On my page, the table scrolling function works when I interact with the table directly. However, I want the scrolling to happen automatically ...

Problem with the datepicker in mgcrea.ngStrap

Encountering an issue with the datepicker feature from the mgcrea.ngStrap library. Here is a glimpse of my layout file setup: <html lang="en-US" ng-app="ftc"> <head> <script src="/assets/2db3448a/components/angular.js/angular.min.js">&l ...

Create a visually appealing HTML5 form using AngularJS ng-model for inputting a phone number and Tax ID number

I am working on improving the appearance and functionality of a basic <input> form field for phone number and tax ID entry. Phone numbers can be in various formats: xxx.xxx.xxxx xxx-xxx-xxxx (xxx) xxx-xxxx Tax IDs may look like: xxx-xx-xxxx xx- ...

The JavaScript code in Three.js is experiencing issues when running in a secure HTTPS environment

After transitioning my website from http to https, I encountered an issue with one of my projects. The background using the Three.js library in this random generator does not show up when the URL is https. However, when the URL is http, the generator wor ...

Understanding the importance of setting constants in global variables for Node.js and Express.js applications

Located in: util/constant.js module.exports = { userTypeAdmin: 0, userTypeUser: 1 }; Needed only once in: app.js ... global.constant = require('./util/constant'); ... Utilized multiple times In: route/index.js console.log(constant.u ...

What is the best way to trigger a tooltip when an input field is clicked?

I want to implement a form that displays tooltips whenever a user clicks or focuses on an input field, and the tooltip should disappear when the user clicks elsewhere. While I understand the basics of using JavaScript's getElementById and click event ...

Having trouble resizing a KineticJs group to 300x300?

Attempting to adjust the size of a kinetic group is resulting in an error message in JavaScript. The Kinetic JS documentation states that setSize should work with group nodes. ...

What is the method for identifying which individual element is responsible for activating an event listener?

While working on a color picker project in JavaScript for practice, I encountered an issue. I needed the #screen element to display the selected color when clicked. How can I determine which color has been clicked and pass its value to the function so that ...

What is the best method for designing a custom mask for the jQuery Masked Input Plugin that accommodates alphanumeric characters, spaces, and accented

Looking for a way to make a custom mask in jQuery Masked Input Plugin that allows alphanumeric characters, spaces, and accented characters? This is what I currently have: $.mask.definitions["A"] = "[a-zA-Z0-9 ]"; $("#input").mask("A?AAAAAAA"); However, ...

Send data with AJAX and PHP without refreshing the page

I have implemented the "add to favorite" feature on my WordPress project using a <form> submission. Each time I click on the add to fav button, it works fine, but the page always reloads which is quite annoying. To tackle this issue, I decided to imp ...

What strategies can be utilized to condense code when needing to adjust a className based on various props?

I am looking to condense this code, particularly the [if~else if] block, in order to dynamically change a className based on different props passed. export default function Button(props) { const { name, height, color, bgColor } = props; let className = ...

JavaScript does not effectively validate emails when integrated with HTML

My goal is to enable users to check if their email address meets the RFC standard by comparing it with the regular expression provided below. I have tested a few examples in the console using a validation function. While I am aware that my regex may not c ...

Updating a specific child element within an array in a MongoDB collection with Mongoose:

I am completely new to working with mongodb/mongoose. Here is an example of a mongoose document that I have: const MySchema = mongoose.Schema({ name: { type: String, minLength: 5, maxlength: 100, required: true }, children: [{ nam ...

Selecting items from a list at random using the power of math.random() and math.floor()

When attempting to randomize the popping of elements in a list stored in the baby variable, only baby[1] is being popped. How can I make it pop random elements? <body> <h1 id="1">bebe</h1> <h1 id="2">t ...

Can you explain the significance of the <%= %> HTML tag?

I've recently been tackling a project with Webpack. For those not familiar, Webpack is a bundler that combines all your files into one final product. One task I encountered was trying to insert one HTML file into another, similar to an import or requ ...

There was a problem with the WebSocket handshake: the response header value for 'Sec-WebSocket-Protocol' did not match any of the values sent

I've encountered an issue with my React project that involves streaming live video through a WebSocket. Whenever the camera firmware is updated, I face an error in establishing the WebSocket connection. Here's how I initiate the WebSocket: wsRe ...

What is the best way to change function.bind(this) to an arrow function in a react native application?

I am attempting to convert my function into an arrow function, but I keep encountering an error of undefined when passing props. <TextInput style={styles.input} value={formState.inputValues.title} onChangeText={textCh ...

Leaving the "OK" button untouched in the sweet alert dialog

While implementing sweet alert in my project, I encountered an issue where the button text was not changing and the cancel button was missing on some pages. On certain pages, it only displayed OK. You can see a screenshot below for reference. https://i.s ...