What is the method for incorporating dates as values and on the X axis within RGraph?

I have been experimenting with the horizontal bar RGraph demo using this code and have found it to be very successful:

let newData = [1, 40, 30];
let hBarChart = new RGraph.HBar('myCanvas', newData);
hBarChart.Set('chart.labels', ['Richard', 'Alex', 'Nick']);
hBarChart.Set('chart.background.barcolor1', 'white');
hBarChart.Set('chart.background.barcolor2', 'white');
hBarChart.Set('chart.background.grid', true);
hBarChart.Set('chart.colors', ['red']);
hBarChart.Draw();

I am wondering if there is a way to incorporate Date objects instead of numbers. I attempted to use something like this but was unsuccessful:

let newData = [new Date(1000), new Date(2000), new Date(3000)];

Answer №1

If that's the situation, you could consider implementing something along these lines:

let data, dates = [new Date("11/16/2011"), new Date("11/17/2011"), new Date("11/18/2011")], labels = [];
// Extracting date information from the date objects
for(let i = 0, len = dates.length; i < len; i++) {
    // Data to be displayed on the graph
    data[i] = dates[i].getDate();

    // Labels for each data entry
    labels[i] = dates[i].getDate() + "/" + dates[i].getMonth() + "/" + dates[i].getYear();  
}
let hbar = new RGraph.HBar('myCanvas', data);
hbar.Set('chart.labels', labels);

/// remainder of the code 

More information about Date object can be found on MDN: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

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

Morris.js tutorial: Enhancing bar charts with data labels

I have this: https://i.sstatic.net/GXjur.png But I want this instead: https://i.sstatic.net/spcS2.png Does morris.js support this feature? If not, what would be the most effective method to implement it? ...

Transforming a 3D coordinate into a 2D screen coordinate [r69!]

I am seeking Three.js code that can convert 3D object coordinates to 2D coordinates within a 'div' element, allowing me to place text labels in the correct positions without them scaling, moving, or rotating along with the 3D movement. Unfortunat ...

Changing the color of an Angular <div> element with scripting

I am currently working on an Angular 6 project and I need to change the colors of a div tag from a script after a click function. However, I also need to change it back to transparent. When I click on the "Inheritance" option, the background color of the ...

Binding Events to Elements within an AngularJS-powered User Interface using a LoopIterator

I am working with an Array of Objects in AngularJS that includes: EmployeeComments ManagerComments ParticipantsComments. [{ "id": "1", "title": "Question1", "ManagerComment": "This was a Job Wel Done", "EmployeeComment": "Wow I am Surprised", ...

Utilize Materialize css with Aurelia for dynamic styling

Looking to incorporate a Materialize CSS select dropdown in the template file order.html. The code snippet is as follows: <div class="row"> <div class="input-field col s12"> <select multiple> <option value="" dis ...

Sorting and Deduplicating MongoDB Data with Reduce

I'm currently using the Reduce function to generate a combined String of fields from an array. For instance, suppose I have an array of subdocuments named children - and each individual child contains a name field. For example: [ {name:"Zak"}, {n ...

Excessive task executions by Node schedule

I have successfully created a daily quote generator that sends an email with a new quote every day. The node-schedule package was instrumental in setting this up. I instructed the program to execute a function every day at 16:00: schedule.scheduleJob("* ...

Displaying results from looping through multiple JSON arrays

Currently, I am traversing through JSON data but encountering multiple arrays in my response. The objective is to exclusively show the killdata response in the line below trHTML += '<tr class="gradeA"><td>' + value.killdata.AcctNo + ...

Error encountered while running a mounted hook in Vue.js that was not properly handled

I have created a To Do List app where users can add tasks using a button. Each new task is added to the list with a checkbox and delete button next to it. I want to save all the values and checked information on the page (store it) whenever the page is ref ...

Is there a way to retrieve both the name of the players and the information within the players' profiles?

Just dipping my toes into the world of Javascript and jQuery while attempting to create an in-game scoreboard for Rocket League, I've hit a bit of a roadblock. Here's the console log output of data from the game: I'm particularly intereste ...

Using AngularJs to implement a $watch feature that enables two-way binding

I am in the process of designing a webpage that includes multiple range sliders that interact with each other based on their settings. Currently, I have a watch function set up that allows this interaction to occur one way. However, I am interested in havi ...

Leveraging server-sent events (SSE) for real-time updates on a web client using JavaScript

I have been experimenting with server-side events (SSE) in JavaScript and Node.JS to send updates to a web client. To simplify things, I created a function that generates the current time every second: setTimeout(function time() { sendEvent('time&a ...

The issue of the marker vanishing upon refreshing the page on AngularJS

Currently, I am encountering a rather peculiar issue. Upon the initial page load, the code snippet below correctly displays a marker at the specified coordinates and ensures the map is properly centered: <div class="paddingtop"> <map data-ng- ...

Tips for creating a scrollable x-axis in d3js

I am struggling to develop a timeline chart using D3.js in angularjs with the ability to scroll along the x-axis to explore data. var rawSvg = element.find("svg")[0]; var width = 1000, height = 300; var svg = d3.select(rawSvg) .attr(" ...

Executing a Java function when a user clicks a button using

I have a situation where I am creating an HTML button using JavaScript and injecting it through Java. The goal is for this button to change activity when clicked. Below is the code snippet: public class WebsiteActivity extends AppCompatActivity implements ...

The functionality of the jQuery .click method appears to be malfunctioning within the Bootstrap

It seems like my JQuery.click event is not functioning as expected when paired with the corresponding button. Any ideas on what might be causing this issue? Here's the HTML CODE snippet: <button id="jan7" type="button" class="btn btn-dark btn-sm"& ...

Issues with grunt - Alert: Task "ngAnnotate:dist" has encountered an error. Proceed using --force option

Encountering an unexpected issue with a Grunt task that previously ran smoothly. The error message is as follows: Running "ngAnnotate:dist" (ngAnnotate) task Generating ".tmp/concat/scripts/scripts.js" from: ".tmp/concat/scripts/scripts.js"...ERROR >& ...

What is the best way to set up v-models for complex arrays or nested objects?

I'm looking to efficiently create multiple v-models for random properties within a deep array, where the position of attributes in arrays/objects can change dynamically. While I've managed to achieve my goal with the current setup, I'll need ...

Numbering the items in ng-repeat directive

I am facing a challenge with my AngularJS directive that is recursively nested within itself multiple times. The issue lies in the fact that the names of items in ng-repeat conflict with those in the outer element, causing it to malfunction. To illustrate ...

Create a search feature based on names utilizing Node Express in conjunction with SQL database

After deciding to create an API with a search feature using SQL queries in node express, this is how I structured my code: app.get('/search/:query', (req, res) => { pool.getConnection((err, connection) => { if(err) throw err ...