私はLine chart
inreact-chartjs
の作成に取り組んでいます。そのため、定期的に API からデータを取得しており、成功するとreducer-state
. Reduxストアに初期データがあります
var lagData = [{
options: {
responsive: true,
legend: {
position: 'top'
},
title: {
display: true,
text: 'ETL lag in minutes'
},
scales: {
xAxes: [{
type: 'linear',
position: 'bottom'
}],
yAxes: [{
stacked: true
}]
}
},
data: {
labels: [],
datasets: [
{
label: 'Current lag',
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
spanGaps: false,
data: []
}
]
}
}]
このストアでは、label
とdata
タグにデータを追加しようとしています。しかし、方法がわかりません。次のように試していますが、機能しません
const lagInfo = (state = lagData, action) => {
switch(action.type) {
case 'GET_CURRENT_LAG_RECEIVED':
console.log(action.data);
return Object.assign({}, state, {
data: Object.assign({}, state.data.datasets.data, {
x: "afsa",
y: "fa"
})
});
break;
case 'GET_CURRENT_LAG_ERROR':
console.log(action.err);
return action.err;
break;
default:
return state;
}
}
export default lagInfo;
どんな助けでも大歓迎です