What is the method for defining field names in Highcharts?

Having experience with Kendo UI charts, I am new to highcharts. In Kendo, we could specify the fieldname for plotting the chart like this:

series: [{
    name: "steps",
    field: "steps",
    categoryField: "createddate"
}]

We could also define the dataSource as follows:

dataSource: dSource

where dSource is an AJAX URL.

I couldn't find a similar approach in the tutorial. The JSON data I have is shown below:

[{"ActivitySummaryKey":174000,
    "id":"kkse2",
    "activityscore":-,
    "activitycalories":456,
    "caloriesBMR":1017,
    "caloriesOut":1412,
    "distances":1.57828236,
    "elevation":0,
    "fairlyActiveminutes":34,
    "floors":0,
    "lightlyActiveMinutes":28,
    "marginalCalories":334,
    "sedentaryMinutes":827,
    "steps":5077,
    "veryActiveMinutes":26,
    "trackersteps":0,
    "trackerdistances":0,
    "trackerfloors":0,
    "trackerelevation":0,
    "trackerActivityCalories":0,
    "trackerCaloriesOut":0,
    "trackerMinutesSedentary":0,
    "trackerminutesLightlyActive":0,
    "trackerminutesFairlyActive":0,
    "trackerminutesVeryActive":0,
    "createddate":"9/17/2014 12:00:00 AM",
    "distanceunit":"Miles"
}]

I aim to plot steps on the y-axis and created date on the x-axis.

Any suggestions on how to achieve this with highcharts?

Answer №1

Utilizing the high-charts data formats is recommended. Refer to series.data for more information.

In order for your points to be visible, ensure that x and y values are set using JSON data (steps and createddate). Additionally, date parsing is necessary (similar to using Date.UTC()).

The expected format for Highcharts is as follows:

[{
    "ActivitySummaryKey":174000,
    "id":"kkse2",
    "activityscore":-,
    "activitycalories":456,
    "caloriesBMR":1017,
    "caloriesOut":1412,
    "distances":1.57828236,
    "elevation":0,
    "fairlyActiveminutes":34,
    "floors":0,
    "lightlyActiveMinutes":28,
    "marginalCalories":334,
    "sedentaryMinutes":827,
    "steps":5077,
    "veryActiveMinutes":26,
    "trackersteps":0,
    "trackerdistances":0,
    "trackerfloors":0,
    "trackerelevation":0,
    "trackerActivityCalories":0,
    "trackerCaloriesOut":0,
    "trackerMinutesSedentary":0,
    "trackerminutesLightlyActive":0,
    "trackerminutesFairlyActive":0,
    "trackerminutesVeryActive":0,
    "createddate":"9/17/2014 12:00:00 AM",
    "distanceunit":"Miles",
    "x": 1410904800000,      // timestamp in ms for Highcharts, extracted from "createdate"
    "y": 5077                // y-value for Highcharts
}]

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

Is it a good idea to relocate the document.ready function into its own JavaScript function?

Can the following code be placed inside a separate JavaScript function within a jQuery document.ready, allowing it to be called like any other JavaScript function? <script type="text/javascript"> $(document).ready(function() { $('div#infoi ...

Unable to access static library Java Script file path using NSBundle

I have integrated a static compiled library into my project, which includes a JavaScript resource. At a specific event in my app, I need to execute the JavaScript file from this library. However, I am facing an issue where the path to the JS file appears ...

How can you ensure a script runs only once another script has completed its execution?

Consider the following code snippet I created to illustrate my idea: var extract = require("./postextract.js"); var rescore = require("./standardaddress.js"); RunFunc(); function RunFunc() { extract.Start(); console.log("Extraction complete"); ...

React JS: Component failing to render

My react component is not rendering and I can't find any bugs. The problem arises when I set the isLoggedIn state to "true", resulting in my HeroSlide not rendering If isLoggedin = false, then: https://i.sstatic.net/JoDSn.jpg If isLoggedIn = true, t ...

Navigating to a specific layout page in AngularJS using ui-router

Hello, I am currently working on an SPA project in angularjs and I have two layout pages set up. On the first layout page (Index.html), there is a tab called Financial. My goal is to redirect to another layout page whenever this tab is clicked. Below is a ...

Is it possible to have a hidden div box within a WordPress post that is only visible to the author of the

How can I create a div box with "id=secret" inside a post that is only visible to the author of the post? I initially made it for the admin, but now I want the id to be visible exclusively to the post's author. For instance: If the author is curren ...

The Angular Material md-input-container consumes a significant amount of space

Currently, I am exploring a sample in Angular Material. It appears that the md-input-container tag is taking up a substantial amount of space by default. The output is shown below: https://i.sstatic.net/hQgpT.png However, I have come across the md-input- ...

The POST request encountered an error with status code 500 while being processed by the Express.js framework in the IncomingMessage

My current challenge involves creating a HTTP request for a CRUD application using JS. The aim is to add a new user account record to the Logins database. However, every time I attempt this request, it results in a 500 error: To test this, I have written ...

The issue arises from the lack of reception of Req and Res parameters in the passport app.use() callback

I have set up the following route using my express middleware: app.use( "/graphql", passport.authenticate("jwt", { session: false }), appGraphQL() ); This route first goes through passport for validation and then connects to my GraphQL server ...

I need help converting the "this week" button to a dropdown menu. Can someone assist me in troubleshooting what I am missing?

Seeking assistance with customizing the "this week" button on the free admin dashboard template provided by Bootstrap 4. Looking to turn it into a dropdown feature but unable to achieve success after two days of research and watching tutorials. See code sn ...

There is an issue with Node/Express not accurately updating the data model

I recently went through a tutorial on creating a RESTful API with Node.js and MongoDB. While it worked well overall, I encountered a few issues. My Player model is as follows: var player = new mongoose.Schema({ name: String, email: String, score: String } ...

Steps for accessing the latest entry in the database

Within my database, there exists the following record: timer_id = 1 time = 498 Despite my efforts to retrieve the record in the 'time' column using the code below, I am unable to fetch the current record: <script> function start(){ ...

Transform MVC4 model into a JavaScript JSON object within a cshtml file

I have a model on my cshtml page that I need to convert into a JSON object for use in the JavaScript on the same cshtml page. I am using MVC4. What is the best way to achieve this? ...

Guide to crafting a custom asynchronous function in a separate file using Express JS

I have a specific function that I want to create called: my_function.js: module.exports = function(req, res, next){ var js_obj; // Do something with the JavaScript object above // Afterwards, I want to append "js_object" to the request object: req.js ...

There was an error in the code: Unexpected token M

Is there a solution for this error that anyone can share? The Google Developer Tools are not able to identify the exact location of the problematic code, making troubleshooting difficult. I am using Meteor and MongoDB. I have looked into Unexpected toke ...

When the function $(document).width() is called, it may yield varying results depending on the timing of the call

Every time I use $(document).width(); within $(window).load(function(){}) or $(document).ready(function(){}), the result differs from when it is called inside $(window).resize(function(){}). The discrepancy is approximately 100px, and it's not due to ...

Issue with JQuery's parentsUntil method when using an element as a variable not producing the desired results

I'm having trouble with a specific coding issue that can be best illustrated through examples: For example, this code snippet works as expected: $(startContainer).parents().each(function(index, parentNode) { if (parentNode.isSameNode(commonConta ...

Shifting Directive Logic to a Method within a Vue Component

I am currently working with a VueJS component that utilizes the style attribute in the following way: <section :style="{ backgroundImage: src && 'url(' + src + ')' }"> ... <script> export default { props: [& ...

Searching for an item within an object to retrieve an alternative element from that very same object

I am currently working on a task that involves checking the data headers to see if they contain 'accept=application/xml', and only then returning the body in XML format. Below is the dataset: [ { url: '/a', status: '200&apos ...

Node is not functioning properly with Discord.js as expected

Having some trouble catching errors in my code. I'm seeing a red line and an expression expected error behind the period after the catch command. Any suggestions? client.on('message', message => { let args = message.content.subs ...