0
저는 아약스를 통해 c3js로 렌더링하는 차트가 여러 개 있습니다. 현재 줄이기를 원하는 반복되는 아약스 코드가 많습니다.c3js 차트 옵션을 함수로 전달합니다.
각 ajax 호출 성공시 c3js 차트가 생성되지만 표시 유형/옵션이 다릅니다. 일반 c3js를 생성하고 옵션을 전달할 수있는 방법이 있습니까? 등 다양한 차트 데이터 유형, 그룹, 열, 축과
$.ajax({
url: url,
data: {'chart': chart, 'start': start, 'end': end},
type: 'post',
dataType: 'json',
beforeSend: function() {
//code
},
success: function (data) {
if (data.success) {
//code
c3.generate({
bindto: '#chart-data',
data: {
columns: data.active,
type: 'area',
groups: [data.groups]
},
axis: {
x: {
type: 'category',
categories: data.span
},
y: {
label: 'Label'
}
}
});
} else {
//code
}
}
});
대한 반복 여러 번
내가 원하는 것은 그러나
var chart_options = {bindto: '#chart-data', data:{columns.data.active} //...
function generateChart(param1, param2, param3, chart_options) {
//do some stuff
//ajax call from above
// ....
// on success:
// c3.generate(chart_options)
}
나는이 방법을 수행, 데이터 때문에 .success 함수 내부이며, 나는 함수를 외부에서 data.active 열을 전달 오전, 나는 정의되지 않은 데이터에 대한 자바 스크립트 오류가 나타납니다.
감사