score:2
Accepted answer
since you want your variables appear in javascript you need to json_encode them. your $label and $data is still in php you can just echo it out into a json.
in your view you can do following
data: {
labels: <?= json_encode($label)?>,
datasets: [
{
label: "population (millions)",
backgroundcolor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: <?= json_encode($data)?>
}
]
},
Source: stackoverflow.com
Related Query
- Accessing data in an associative array in CodeIgniter 3
- using array values in chart.js data and label field
- Can't pass array to chart.js which got its data from @Input
- Laravel 5.1 format date array for chart.js data
- How to select and pass array object to data setting of chart.js config?
- How to make a chart with an associative array with chart.js?
- Dynamically populate array with Firebase Data Vue.js
- Passing data to highcharts from javascript array or variable
- I can't add data to chartjs from codeigniter
- Chartjs barchart generate data for an array dataset
- Passing an Array from a Flask view to the javascript code of another view
- Rendering Chart.js Bubble Chart Using Array Data
- Load data from a JSON object into an array
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- How to Convert an Array of Objects into an Object of Associative Arrays in Javascript
- Converting JSON data into Chart.js array from strings
- Inserting data from controller to an array in javascript
- Update the chart data from an array stored in a variable on button click
- How to get the database data into ChartJS using codeigniter
- accessing returned data from a states resolve function
- Passing JSON data from PHP array into ChartJS
- Chart JS how to display an array of data objects as bar chart
- Put array in chart data
- chart js not dispalying data array that comes from an axios request
- Chart JS can't access data from array within an object
- Referencing locally declared variable into an array for data for chartjs
- How to write better code in es6 for formatting an object with array values
- Php add dummy data to array
- Ionic 3 + Angular 4 + chart.js - loading data from array
- ChartJS have xAxes labels match data source
More Query from same tag
- My choice of color is not used in my stacked bar chart
- Chart.js Adapting different X axis with same scale
- Unable to get the expected legend shown in chart js
- Chart.js HTML custom legend issues with doughnut chart
- So, I'm fetching my data from phpMyAdmin MySQL to the chart.js, but I need it with AJAX, but how AJAX works with Chart.js?
- Chart.js: Display Custom Tooltips, always visible on stacked bar-chart
- How to Convert an Array of Objects into an Object of Associative Arrays in Javascript
- API data not loading in chart.js until element is inspected or page is resized
- Chart.js: Combined Line and Bar Data
- ChartJS: Get individual values minus another value in the custom legend
- Append suffix to Chart.js dataset?
- Chart.JS TypeError: this.scale is undefined
- Angular chart how to show the legend data value by default along with legend name
- How to add text inside scatter plot using Chart.js?
- ChartJS: Horizontal Bar with multiple datasets not showing Bars
- Radarwidth beyond label chart.js
- Chart,js Pie Chart can the gap between a pie chart and the legend be adjusted
- Chart JS custom tooltip not showing
- How to get certain text from json object value
- chart.js pie chart issue with display: none
- How to invert scale display on radar chart (chart.js)
- (chart.js v3.5.1) change bar background, label font color on click
- Charts.js - Bubble chart with two word axis
- Execute chartjs after an ajax call with PHP
- How to add left/right padding in Chart.js bar chart?
- Inserting Graphs into DomPDF
- Switching between different Chart.js charts using the same canvas
- chart cannot read multiple datasets from the back-end (single data is fine)
- ERROR TypeError: Cannot read property 'testMethod' of undefined
- Moving the zerolines in ChartJS scatter chart