javascript - C3 bar chart unknown number of bars -
javascript - C3 bar chart unknown number of bars -
i using c3.js create bar chart.
my case such:
i want collect x
number of info , display them in chart have created next script:
$.ajax({ type: 'post', url: '/academystat/academy_module_user_report', datatype: 'json', data: { request: 'ajax', team_id: team_id, module_id: module_id }, success: function (data) { if(data != null) { (var = 0; < data.length; i++) { var add_data = [data[i]['name'], data[i]['score']] char_data.push(add_data); } var chart = c3.generate({ bindto: '#score_chart', data: { columns: [ char_data ], type: 'bar' } }); } } });
as can see above illustration looping through info , adding array untill have array of array's (unknown number of data).
however when run in browser next error in console
:
error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 286.6,nan l286.6,nan l531.4,nan l531.4,nan z" d3.min.js:5 error: invalid value <path> attribute d="m 1102.6,nan l1102.6,nan l1347.3999999999999,nan l1347.3999999999999,nan z
however if instead utilize method pop
info displayed fine. problem pop();
have know how many arrays char_data
array has , impossible me know.
has tried similar or know how might prepare issue?
it looks setting charts columns
array within array columns: [ [ ['name', 'score'] ] ]
change columns: [ char_data ]
columns: char_data
$.ajax({ type: 'post', url: '/academystat/academy_module_user_report', datatype: 'json', data: { request: 'ajax', team_id: team_id, module_id: module_id }, success: function (data) { if (data != null) { (var = 0; < data.length; i++) { var add_data = [data[i]['name'], data[i]['score']] char_data.push(add_data); } var chart = c3.generate({ bindto: '#score_chart', data: { columns: char_data, type: 'bar' } }); } } });
javascript arrays c3.js
Comments
Post a Comment