score:1
this is an asynchronous vs synchorous error. this tutorial may help a bit.
take a look at this part of the code:
function bardata(url){
let data_labels = [];
let data_values = [];
$.ajax({
url: url,
type: 'get',
async: false,
success: function(bar_data){
data_labels= bar_data.labels;
data_values= bar_data.values;
}
})
return {data_labels,data_values};
}
the return {data_labels,data_values};
is actually happening before the $.ajax
call. if you want to return the results from the server this line should be inside the success
function of the ajax call. take a look at this question where the op has the same issue.
about updating a chart, here is a demo with a mocked server response that updates its values each second: https://codepen.io/adelriosantiago/pen/yzpnlbd
Source: stackoverflow.com
Related Query
- How to create Bar chart that gets updated from new ajax requests with ChartJS?
- How to create chartjs chart with data from database C#
- How can I create a stacked bar chart with Charts.JS that displays relative rather than absolute values?
- ChartJs - stacked bar chart with groups - how to create second x-axis with stack id
- ChartJS - would like to create a mixed chart with horizontal Bar and a dot to represent the answer from the current user
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- How do I create a stacked horizontal bar chart with Chart.js in React?
- How to create a chart with chartjs.org with data from an array?
- How to load new chart (chartsjs) from api call with jquery?
- how to insert dynamic data from sql into chartjs stacked bar chart javascript
- How to create a chart.js scatter chart with data from two lists
- How can I create a bar chart that has multiple yAxes scales?
- How to bind data from Controler to chartjs line chart to create it as dynamic?
- how to create a bar chart with php data variables
- How to create rounded bar graph with Angular 7 and Chartjs (v2)
- How to take data from an API and create a chart on that using Chart.js and Angular 8?
- How to create Stacked bar chart from JSON in chart.js
- ChartJS Create New chart from variable
- how to create bar chart with group and sam color for each group using chart.js?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to prevent first/last bars from being cut off in a chart with time scale
- Chart.js Bar Chart - how to chart bars from 0
- chartjs : how to set custom scale in bar chart
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to create stacked bar chart using react-chartjs-2?
More Query from same tag
- Data not displaying in django admin - using chart.js (no errors)
- ChartJS set default axis
- Dynamically create dataset objects for multi-line graphing, using pre-defined dataset object arrays (JavaScript / Chart.js)
- How to display "%" sign on mouse hover in Pie-Chart
- Chartjs sample can't be reproduced
- Using Charts.js with react
- chartJS line chart not plotting values that are less than minY
- Chart.js 2.1.6 background color for each section
- How to get value of defaultdic in JS (Django framework)?
- Chart.JS value on top disappear when tooltip show up
- Chart JS add max value to legend
- Displaying multiple line graphs on one page
- Multiple labels for multiple data-sets in chart.js
- Get X, Y onClick chart coordinates in ChartJS
- How to add a toggle inside a title of the barchart js
- (Lifecycle problem?) React Chart js-2 not updating data from componentDidMount
- start y-axis from 0 in ng2-charts
- call Column that is complex in query
- How to increase space between chart and legend? (googlecharts)
- How to install Chart.js and angular-chart.js (Error: Chart.js library needs to be included)
- White Space in stacked bar using chart.js
- How to scale label size radar chart chart.js
- ChartJS rotate 90' but keep text straight
- Does the chartjs supports localization?
- Loading multiple doughnut chart from chart.JS in a single component of angular 6
- Labels for Nested Doughtnut Chart React ChartJS
- chartjs bar chart filter using datetimepicker
- Chart.js Globally Formatted Number Labels
- How can I draw dotted line using chartjs?
- How to disable a custom tooltip for a dataset in Chart.js line chart?