score:3
Accepted answer
json_encode()
produces a JSON string. You need to parse
this with JSON.parse()
before you can use it.
$.ajax({
type: 'POST',
url: 'templates/getdata.php',
success: function (data) {
lineChartData = JSON.parse(data); //parse the data into JSON
var ctx = document.getElementById("OmzetChart").getContext("2d");
var myLineChart = new Chart(ctx, {
type: 'line',
data: lineChartData
});
}
});
Also, using $.ajax()
method's dataType
parameter, you can leave this parsing to jQuery.
$.ajax({
type: 'POST',
url: 'templates/getdata.php',
dataType: 'json', //tell jQuery to parse received data as JSON before passing it onto successCallback
success: function (data) {
var ctx = document.getElementById("OmzetChart").getContext("2d");
var myLineChart = new Chart(ctx, {
type: 'line',
data: data //jQuery will parse this since dataType is set to json
});
}
});
Source: stackoverflow.com
Related Query
- How to display data labels outside in pie chart with lines in ionic
- How populate chart.js with sql data?
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Angular chart how to show the legend data value by default along with legend name
- How to create chartjs chart with data from database C#
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- How to use JSON data in creating a chart with chartjs?
- How to display chart using Chartjs with JSON data in Laravel
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How to create a chart with chartjs.org with data from an array?
- how to write labels along with data on top and bottom of each stack in bar chart
- How write the labels of the data inside a Doughnut Chart made with Chart.js?
- How to dynamically update data of line chart used with chart Js?
- How to get data on chart based on selected date (Filtering data Chart JS with datepicker)
- how to insert dynamic data from sql into chartjs stacked bar chart javascript
- How do I destroy/update Chart Data in this chart.js code example?
- Changing chart data dynamically with C# from SQL database
- How to create a chart.js scatter chart with data from two lists
- how to create a bar chart with php data variables
- How to create a chart-js pie chart with PHP data variables?
- How can I add new data points to an existing chart with chart.js?
- How to generate multi bar chart in Chart.js with php & sql
- How can I build some chart with Chart.js and ng2-charts using an array of revenus & budgets per month date as Data source?
- How to fill my chart (chart.js) with my own data from API
- How to set data values as labels in Chart.js with a Radar Chart
- 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
- How to prevent first/last bars from being cut off in a chart with time scale
- ChartJS - Draw chart with label by month, data by day
- line chart with {x, y} point data displays only 2 values
More Query from same tag
- Can i set dynamic step size on stepped line chart in chart.js?
- Chart.js group data by month\year
- How to get Data from API to display chart using chartjs in Vuejs
- Chart.js need to fix x axis number of vales
- Pause horizontal scrolling in chart.js for real time data
- Firefox is not responding when loading 800+ data sets in Bar Chart with Charts.Js
- Angular 2 Chart.js and NG2-Charts Not Binding Data Objects After Updates To Project
- How to display legend in toolbox in Charts.js?
- Chartjs annotations-plugin: Can I add multiple vertical lines to identically named x-axis labels?
- Add Link to X-Label Chart.js
- ChartJS tooltip when having multiple lines on a time graph
- Django Serializers - Return the sum of values by filter
- How do I force Chart.js axes min and max with react-chartjs-2?
- How to set up a simple pie chart using React in ChartJS on codesandbox
- getBoundingClientRect gives incorrect value
- ChartJS Y Axis scale odd
- How can we build charts on Polymer 1.0 using Chart.js?
- ChartJs in endless loop
- ChartJS width undefined in React Typescript
- Copy div content to dynamically create a modal window:possible?
- How to print multiple items with the same charts? any directions?
- Chartjs showing labels for bidimensional array
- chart.js why are my hover effects not working?
- Is it possible to pot a line chart of date vs time in ChartJS?
- I need to build an array of arrays, having trouble conceptualizing
- Is it possible to add a javascript chart in a webview in Xamari.Forms
- How to set responsive width and height of canvas?
- Partitioning radar graph in chart.js by sector
- Chart.js will not render using vue.js until window resizes
- angular chartjs line chart default options