Sencha chart series 초기화
2024. 11. 24. 22:45ㆍ카테고리 없음
series를 동적 처리할때, chart.setSeries([]); 처럼 초기화를 해줘야 함
// Assume you have a chart component with an ID of 'myChart'
let chart = Ext.getCmp('myChart');
// Function to update series dynamically
function updateSeries(data, xField, yField) {
if (!chart) {
console.error('Chart not found!');
return;
}
// Remove existing series
chart.setSeries([]);
// Add a new series dynamically
const newSeries = {
type: 'line', // or 'bar', 'scatter', etc.
xField: xField,
yField: yField,
marker: {
type: 'circle',
radius: 5
},
label: {
field: yField,
display: 'over' // Show data labels
}
};
// Update chart with new series and new store data
chart.setConfig({
series: [newSeries],
store: {
fields: [xField, yField],
data: data
}
});
// Redraw the chart after updates
chart.redraw();
}
// Example usage of the function
let newData = [
{ category: 'A', value: 10 },
{ category: 'B', value: 20 },
{ category: 'C', value: 30 }
];
updateSeries(newData, 'category', 'value');