Issues with data presentation on Chart.js line graph

I am currently troubleshooting why my data isn't appearing on the chart. It seems like the issue might be related to ticks, although I can't be certain. Strangely, there are no errors showing up in the console, even though all the data is being retrieved correctly. Perhaps there's something wrong with the options settings that I have overlooked. Despite attempting to follow the documentation and sample code provided, I'm still unable to get it working.

To provide some context, the chart is located within a Vue component and is intended to show the number of open and closed tickets per day over a 2-month period. The data is passed into the component through props.

You can see how the chart looks at the moment: https://i.sstatic.net/I6mut.png

Below is the current code for the chart:

export default {
    props:['created', 'closed','labels'],
    mounted() {
        require('chart.js');

        Chart.defaults.global.defaultFontColor = "#fff";
        Chart.defaults.global.defaultFontFamily = "Roboto";

        console.log(this.labels);
        console.log(this.closed);
        console.log(this.created);

        var mychart = new Chart(document.getElementById("chart"), {
            type: 'line',
            maintainAspectRation:true,
            labels: this.labels,
            data: {
                datasets: [{
                        fill: false,
                        label: 'Tickets Created',
                        backgroundColor: '#e52d27',
                        data: this.created
                    },
                    {
                        fill: false,
                        label: 'Tickets Closed',
                        backgroundColor: '#00FF58',
                        data: this.closed
                    },
                ]
            },
            options: {
            responsive: true,
            title: {
                display: true,
                text: 'Ticket Trend'
            },
            scales: {
                xAxes: [{
                    display: true,
                    scaleLabel: {
                        display: true,
                        labelString: 'Month'
                    }
                }],
                yAxes: [{
                    display: true,
                    scaleLabel: {
                        display: true,
                        labelString: 'Value'
                    },
                    ticks: {
                        min: 0,
                        max: 20,
                    }
                }]
            }
        }
        });
    }
}

And here are the values of this.labels:

["12-05-18", "12-06-18", "12-07-18", "12-10-18", "12-11-18", "12-12-18",
"12-13-18", "12-14-18", "12-17-18", "12-18-18", "12-19-18", "12-20-18", 
"12-21-18", "12-24-18", "12-25-18", "12-26-18", "12-27-18", "12-28-18", 
"12-31-18", "01-01-19", "01-02-19", "01-03-19", "01-04-19", "01-07-19", 
"01-08-19", "01-09-19", "01-10-19", "01-11-19", "01-14-19", "01-15-19", 
"01-16-19", "01-17-19", "01-18-19", "01-21-19", "01-22-19", "01-23-19",
"01-24-19", "01-25-19", "01-28-19", "01-29-19", "01-30-19", "01-31-19",
"02-01-19", "02-04-19"]

this.closed:

[0, 0, 0, 0, 10, 0, 0, 0, 0, 10, 0, 20, 10, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0,
 3, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 6, 0, 0, 2, 0, 0, 0, 0]

this.created:

[0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 2, 0, 0, 20, 0,
 0, 0, 0, 0, 10, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Answer №1

Make sure to include your labels within the data object, like so:

data: {
    labels: this.labels,  // <--- This 
    datasets: [{
            fill: false,
            label: 'Total Sales',
            backgroundColor: '#ff9900',
            data: this.salesData
        },
        {
            fill: false,
            label: 'Expenses',
            backgroundColor: '#3366cc',
            data: this.expenseData
        },
    ]
},

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

Implementing a Variety of Textures and Images in a Three.js Scene

I am utilizing THREE.js to showcase a 3D spinning globe in the web browser. Along with that, I intend for an image to display around the rotating globe. Despite attempting to use the provided function, var img = new THREE.ImageLoader(); img.load("texture/ ...

I am unable to retrieve the values from a manually created JavaScript list using querySelectorAll()

const myList = document.createElement("div"); myList.setAttribute('id', 'name'); const list1 = document.createElement("ul"); const item1 = document.createElement("li"); let value1 = document.createTe ...

Cross-site communication with Ajax using both POST and GET requests

As a beginner in JavaScript, I'm facing challenges with implementing ajax POST and GET requests. While I can successfully do it using Google Postman as shown here https://i.sstatic.net/Cegxj.pnghttps://i.sstatic.net/ovJT0.png, the problem arises when ...

How to efficiently manage multiple objects as a unified entity in Three.js

Hello, I am new to the world of three.js and I am facing a challenge. I want to combine multiple objects into one single entity, essentially creating a bas-relief effect. Specifically, I need to render the following elements: A box geometry serving as th ...

Ways to replicate inputting into a textarea field with Javascript or Jquery?

I am currently working with a textarea that utilizes a jquery plugin to automatically resize as the user types. However, I am encountering an issue where users are unable to fully view and edit previously typed messages due to the default settings of the t ...

What is the best way to deploy a REST API utilizing an imported array of JavaScript objects?

I have been using the instructions from this helpful article to deploy a Node REST API on AWS, but I've encountered a problem. In my serverless.yml file, I have set up the configuration for the AWS REST API and DynamoDB table. plugins: - serverless ...

I'm struggling to grasp how to effectively utilize a JSON Object in this situation

In my coding project, I am looking to utilize Javascript in order to create a JSON or array that will house pairs of data for 'id' and 'ip'. This way, if I need to retrieve the 'ip' for a specific 'id=123', I can eas ...

Issue with Tailwind classes not applying correctly upon refreshing the page in production settings

Challenge Description: Encountering an issue with my nextjs project that utilizes tailwindcss. The login page initially loads with the required classes for the UI, but upon refreshing the page, the classes disappear from the DOM, causing a broken UI. Her ...

What is the best approach to dynamically load html table cell data into a table with changing headers in a React application?

Currently, I am in the process of developing a <table> using React version 0.14.6. This table consists of column headers that are dynamically added to the <thead> section of the table: CourseTable.js: import CourseList from './CourseList ...

Can someone help me figure out how to make my Dropdown stay open when I highlight input, drag, and release

While working with the react bootstrap Dropdown component, I've encountered a specific behavior that is causing some trouble. To better illustrate the issue, I've attached some images. In my dropdown, there is an input filter box along with a li ...

Utilize information from a JSON Array to populate a JavaScript Array

Is there a way to link the data from the $data variable in ajax.php to the this.products[] array in store.js? Both files are separate, so how can I achieve this? The webpage displays the database data returned by ajax.php as shown below: [{"0":"100001"," ...

"Exploring the blend of VueJS, ExpressJS, and MySQL in architectural design - A deep dive into

What is the architectural structure of my Vue.js + Express.js + MySQL application? I am tasked with detailing the design of my app for a project, but I'm uncertain about what to name or classify it as. Vue.js (Frontend) Primarily focuses on managin ...

Manipulating arrays within Vuejs does not trigger a re-render of table rows

I have successfully generated a user table using data retrieved from an ajax request. The table has a structure similar to this: [Image of Table][1] Now, when an admin makes changes to a user's username, I want the respective row to update with the n ...

What is the correct way to extract results from an Array of Objects in Typescript after parsing a JSON string into a JSON object? I need help troubleshooting my code

Here is my code for extracting data from an array of objects after converting it from a JSON string to a JSON object. export class FourColumnResults { constructor(private column1: string, private column2: string, private column3: string, priv ...

How to prevent users from selecting certain options using angular's ng-options

As per the Angular documentation ng-options guidelines I tried to implement this piece of code: <select ng-model="model" ng-options="item.CODE as item.NAME disable when item.DISABLE for item in list" id="foo" name="foo" ng-change="change()"> Howe ...

Tips on resolving JavaScript's failure to adjust to the latest HTML inputs

I'm working on a homepage where users can choose their preferred search engine. The issue I'm facing is that even if they switch between search engines, the result remains the same. I've experimented with if-then statements, but the selecti ...

Does the webworker function as a multi-thread?

For example: worker.postMessage(data1); worker.postMessage(data2); If there are multiple issues to be dealt with inside the web worker, would worker.postMessage(data2) block before completing data1? ...

Activate Popover on Third Click with Bootstrap 4

Is it possible to create a button that triggers a popover after 3 clicks and then automatically dismisses after one click using Bootstrap v4.3.1? Code: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.mi ...

Activate dark mode automatically in material-ui

According to the official documentation: The documentation mentions that a dark mode theme will be automatically generated and reflected in the UI, but I am encountering issues with it. Dependencies: "@emotion/styled": "^11.0.0", ...

Ways to access component load status in Next.js

I'm currently developing a basic Pokedex to showcase all Pokemon. I am utilizing a map function on an array of Pokemon objects to display all the cards in this manner: {pokemons.results.map((el, i) => { return ( <di ...