score:2
Accepted answer
you can set the labels
using .map()
method on mydata
array like:
data: {
labels: mydata.map(d => d.region),
....
},
edit:
you can create a new function and add all chart init code into it like:
function createchart() {
new chart(document.getelementbyid("chart"), {
type: 'horizontalbar',
data: {
labels: mydata.map(d => d.region),
... you code here
},
...
});
}
createchart();
and then on gridview
click, again call this createchart
function in the end like:
$("#gridview").click(function() {
// all your code logic here
console.log(mydata);
createchart();
});
Source: stackoverflow.com
Related Query
- bind first property value of an array of object into chart.js
- Chartjs - Set start and end value into a Bar Chart
- How to use segment property to color line / border color based on value in chart js?
- How to add null value rows into pandas dataframe for missing years in a multi-line chart plot
- Angular / ng2-charts: Fetching json data in chart object showing: Cannot read property 'length' of undefined
- Chart only prints out first value using jquery ajax php
- Load data from a JSON object into an array
- How to Convert an Array of Objects into an Object of Associative Arrays in Javascript
- Chart JS can't access data from array within an object
- How to write better code in es6 for formatting an object with array values
- Put the value into the doughnut chart
- Chart.js - Multiple JSON data object array [{x: Date, y: count}....] representing each dataset of the chart
- How to push an array into an Object which is inside of another array?
- getting additional value fields from data source for dx.chartjs doughnut chart
- Passing data to a chart javascript object and array
- Displaying the first value of the array in datasets.label Chartjs
- Not being able to display value from json data into chart js
- Chart.js br chart only displaying first value
- First implementation - Chart object seems to be incomplete
- Object list into chart labels not working
- ChartJS: call the property of an array object in the tooltip
- How to access custom property in dataset object in Bar Chart in React ChartJS 2?
- NG2-Charts Can't bind to 'datasets' since it isn't a known property of 'canvas'
- Chart Js Cannot read property 'length' of undefined
- Can't bind to 'data' since it isn't a known property of 'canvas'
- Chart.js: bar chart first bar and last bar not displaying in full
- Get Chart js object from selector
- How to display value of only one datapoint in line chart
- How to add datas to chart js from javascript array itself?
- get yLabel value onclick chart js
More Query from same tag
- Add background text in ChartJS
- Updating data in chart.js
- Clojurescript/Reagent/Chart.js - Reagent life cycle - chart.update()
- ChatJS 2.8 chaning x-Axis font style and color
- ChartJs custom tooltip position
- charts.js straight lines - i cant find a solution
- How to fix the distance between horizontal points (x-axis) in chartJS
- Load data from Google Analytics in a Chart.js chart
- How to create a chart that uses strings for both the X and Y axes?
- how to get multiple x-axis labels for a react-chartjs-2 chart
- Chart.js - How to remove percentage data labels?
- Can Chart.js combines Line Chart and Bar Chart in one canvas
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- Can I plot random points on a chart.js or Google Charts chart?
- Pie chart.js - show all 3 segment borders
- Vuejs - Chartjs doesn't render my own options with api request
- chartjs how to apply after animation
- Chart.js doesn't animate on first load
- How to plot dates in Chart.js
- Border radius for the bar chart in ChartJS
- Chart.js - Multiple Line Charts - [2]
- chart.js, after each update, avoid scrolling to top position
- How do I increase the space between the Legend and the Chart when using angular-chart.js?
- how to write labels along with data on top and bottom of each stack in bar chart
- Can't change labels' font color. Chartkick Ruby on rails
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- ChartNew.js - Remove/Hide zero label from Pie Chart
- chartjs data labels - character level font colour control
- How do I loop under Chart js in JavaScript for multiple axis?
- How do I implement Laravel Analytics with Chart.js