I'm trying to create a chart with a time axis in Vue using Chart.js. When I set the data right in the Data object like so, everything works correctly:
chartData: {
datasets: [
{
backgroundColor: '#ED645A',
borderColor: '#ED645A',
fill: false,
data: [
{
t: new Date("1998-1-1"),
y: 7.1
},
{
t: new Date("1998-2-1"),
y: 8.4
},
{
t: new Date("1998-3-1"),
y: 18.5
},
{
t: new Date("1998-4-1"),
y: 16.2
},
{
t: new Date("1998-5-1"),
y: 18.4
}
]
}
]
},
But when I'm trying to load the data from JSON and form the datasets object in computed property, like so, it doesn't work:
import pureSecondDatasetJson from "../assets/pureSecondDataset.json"
...
export default {
...
data () {
return {
pureSecondDataset: pureSecondDatasetJson,
charts: [
chartData: {
datasets: this.foo
},
...
computed: {
foo() {
var plotData = []
for (var i=0; i<this.pureSecondDataset.length; i++) {
plotData.push({t: new Date(this.pureSecondDataset[i].t), y: this.pureSecondDataset[i].y})
}
var chartData = [
{
backgroundColor: '#ED645A',
borderColor: '#ED645A',
fill: false,
data: plotData
}
];
return chartData
}
}
The object, created in computed seems the same as the one, which put directly, so why it doesn;t work?