The absence of multiple lines on the x-axis in the linear chart was noticeable

Currently, I am facing an issue with loading a single axis line chart on my Dashboard.vue. The functionality involves users selecting a 'year' and a 'loan_type' from dropdown menus, after which the chart should display a 12-month record of 'annual_payment' and 'scheduled_payment' as linear lines.

Dashboard.vue

<div class="card-header bg-white p-2">
    <div class="row justify-content-md-between">
       ...
    </div>
</div>
<div class="card-body">
  ...
</div>

.
.

<script>
  export default {
    ...
  }
</script>

AjaxDataController.php

.
.

public function annual_payment(Request $request) {
    ...
}

.
.

If anyone could provide insight on where my mistake lies and how to correct it because the chart is not loading any data at the moment, it would be greatly appreciated.

Answer №1

Within datasets, there are 2 distinct objects. Each object is equipped with a data property.

The array of

[$payment_amount, $scheduled_amount]
is being assigned to the data property of the first object.

To clarify, it seems like you intend to assign $payment_amount to the first object and $scheduled_amount to the second object.

Consider the following approach

 let jsonData = response.data;
 this.chart_data.annual_payment.datasets[0].label = year;
 this.chart_data.annual_payment.datasets[0].data = jsonData[0];
 this.chart_data.annual_payment.datasets[1].data = jsonData[1];
 this.is_loaded.annual_payment = true;

Answer №2

AjaxDataController.php

public function calculate_annual_payment(Request $request) {
    $data = [];
    $data1 = [];
    $data2 = [];
    $selected_loan_type = $request->loan_type;
    $selected_year = $request->year;

    for($i=0; $i<12; $i++) {
        $dt = \Carbon\Carbon::createFromFormat('Y-n', $selected_year.'-'.($i+1))->format('Y-m');
        $payment_amount = \App\Payment::where('loan_type_id', $selected_loan_type)
            ->where('paid_at', 'like', $dt.'%')->sum('amount');
        $scheduled_amount = \App\Payment::where('loan_type_id', $selected_loan_type)
            ->sum('scheduled_amount');
        $data1[$i] = $payment_amount;
        $data2[$i] = $scheduled_amount;
    }  
    $data = [
        'payment_amount' => $data1,
        'monthly_amount' => $data2
    ];
    return $data;
}

Dashboard.vue

.
.
            axios
            .post(api_url, data)
            .then(response => {
              var json_data = response.data;
              this.chart_data.annual_payment.datasets[0].label = selected_year;
              this.chart_data.annual_payment.datasets[0].data = json_data.payment_amount;
              this.chart_data.annual_payment.datasets[1].data = json_data.monthly_amount;
              this.is_loaded.annual_payment = true;
            })
            .catch(error => {
              console.log('error',error);
              this.is_loaded.annual_payment = true;
            });
.
. 

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

Error Message: Unhandled TypeError - Unable to access property 'setState' as it is null in React

Encountering an issue on my React page where I receive the error: Uncaught TypeError: Cannot read property 'setState' of null specifically when trying to use the counter component. The problem seems to originate from the usage of this inside th ...

Guide on dynamically changing the color of polymer 1.0 paper-button from an array of colors

I have an array called buttonColors that contains a set of colors in hex format. I am looking to create paper-buttons, each with the color from the buttonColors array. How can I achieve this in Polymer 1.0? <template is="dom-repeat" items="{{buttonCo ...

Ensure that the context is used to effectively clear any existing data from the previous bar chart

I recently came across a cool codepen demo on this link. Upon clicking the first button followed by the second, the data transitions smoothly. However, there seems to be an issue where when hovering randomly over the bar charts at this source, the value ...

Incorporating OpenLayers and TypeScript: Issue with Event.map.forEachFeatureAtPixel, where the argument type is not compatible with the parameter type

I am currently attempting to implement Open Layers v7.2.2 with TypeScript. {When not using TypeScript, the code functions properly} function OnMapClick(event: MapBrowserEvent<UIEvent>) { event.map.forEachFeatureAtPixel(event.pixel, function(curren ...

Obtaining a response in string format using the $.ajax function

var module = (function(){ return{ loadData: function(url, success, error){ $.when($.ajax({ type: 'GET', cache: false, url: url, contentType: 'application ...

Uncaught TypeError: Cannot create new instances of User - Node.js server not recognizing User as a constructor

I encountered an issue while attempting to save a user to MongoDB database using a post request. The error message "TypeError: User is not a constructor" keeps popping up despite the straightforward setup of my code. I have double-checked but can't se ...

Utilizing Regular Expressions in Sails.js Routing

Currently, I am working on a sails.js project and utilizing backbone for the front end. My goal is to have a single route leading to the index page where my backbone application is hosted. '/*': { view: 'home/index' } This setup ...

Can one validate a single route parameter on its own?

Imagine a scenario where the route is structured as follows: companies/{companyId}/departments/{departmentId}/employees How can we validate each of the resource ids (companyId, departmentId) separately? I attempted the following approach, but unfortunate ...

the process of triggering animation to start automatically when a button is clicked in Web Development

I'm looking to create a React component that triggers an animation when clicked. I have a few options in mind: If the props are changed in the middle of the animation, it should restart the animation. The props can be changed by clicking a button on ...

Unable to submit /api/sentiment

I'm currently troubleshooting the /api/sentiment endpoint in postman and encountering a "cannot POST" error. I have confirmed that the routes are correct and the server is actively listening on port 8080. Interestingly, all other endpoints function wi ...

Seeking assistance with downloading a collection of images as a zipped file using AngularJS

My code was previously working with jszip 2x but now I'm getting an error stating "This method has been removed in JSZip 3.0, please check the upgrade guide.". Even after following the upgrade guide, my code is still not functioning properly. I need a ...

Using Vue to transfer data from one component to another by passing props to an element

I'm currently exploring a method to pass a Vue prop to the a tag within the second component. It needs to be a dynamic prop, so I cannot specifically import it into the component. First fragment <script> export default { name: 'first&apo ...

Designing a file upload progress bar with the help of jquery and ajax

I am looking to implement a progress bar for uploading files utilizing jquery and ajax. Here is the jquery code I have written: function updateProgress(evt) { // evt is an ProgressEvent. if (evt.lengthComputable) { var percentLoaded = ...

How can I ensure that the form submit event is delayed until the onChange event is completed when using jQuery?

Imagine a scenario where a textbox on a webpage has a 'change' event attached to it using jQuery. $('.myFormClass').on('change', '.amount', function () { // An AJAX call is made here, and the respons ...

Is the javascript function I created not recognized as "a function"?

A small .js file containing 3 functions for easy in-site cookie management was created. Below is the source code: // Create Cookie function Bake(name,value) { var oDate = new Date(); oDate.setYear(oDate.getFullYear()+1); var oCookie = encodeURIComponent(n ...

What causes these queries to function separately but fail when combined?

I am facing an issue with combining 2 queries in my Firestore collection. These are the 2 examples that work: database .collection('servicebonnen') .where('medewerker', '==', 'CEES') and: database .collecti ...

Contrasts in the immutability strategies of Vuex and Redux

After exploring Vuex and noticing how simple it is to mutate states with mutation handlers using basic assignment, I am currently delving into redux. I have come to realize that redux emphasizes immutability, which can make coding a bit more verbose. This ...

Angular 8 delivers an observable as a result following a series of asynchronous requests

I am working on a simple function that executes 3 asynchronous functions in sequence: fetchData() { this.fetchUsers('2') .pipe( flatMap((data: any) => { return this.fetchPosts(data.id); }), fl ...

Getting a value from a Child component to a Parent component in Nuxt.js - a step-by-step guide

I am facing a challenge in passing data from Child A component to Parent, and then from the Parent to Child B using props. In my project using nuxt.js, I have the following structure: layouts/default.vue The default template loads multiple components wh ...

Managing the position of the caret within a content-editable div

I need help with editing a contenteditable div in HTML <div contenteditable="true" id="TextOnlyPage"></div> Here is my jQuery code: var rxp = new RegExp("(([0-9]+\.?[0-9]+)|([0-9]+))", "gm"); $('#TextOnlyPage').keyup(function( ...