Reputation: 53
I am trying to build a very simple chart using FusionCharts where I can show data in a time-axis chart. I followed examples on the official website, but my chart won't jump to the set initial date for the x-axis. Instead, my chart is initially set to January 1970, which to my knowledge is the minimum date value on UNIX-based machines.
const data = [["2020-01-01",0],["2020-01-02",2],["2020-01-03",6],["2020-01-06",4],["2020-01-07",12],["2020-01-08",13],["2020-01-10",5],["2020-01-11",23],["2020-01-20",26],["2020-01-21",22],["2020-01-22",17],["2020-01-23",30],["2020-01-24",27],["2020-01-28",28],["2020-02-02",23],["2020-02-03",33]]
const schema = [{"name":"Date","type":"date","format":"%d-%b-%y"},{"name":"Value","type":"number"}]
const dataStore = new FusionCharts.DataStore();
const dataSource = {
chart: {},
caption: {
text: "Sales Analysis"
},
subcaption: {
text: "Grocery"
},
yaxis: [
{
plot: {
value: "Grocery Sales Value"
},
format: {
prefix: "$"
},
title: "Sale Value"
}
],
xaxis: {
initialinterval: {
from: '2020-01-01',
to: '2020-01-31',
}
}
};
dataSource.data = dataStore.createDataTable(data, schema);
new FusionCharts({
type: "timeseries",
renderAt: "chart-container",
width: "100%",
height: "500",
dataSource: dataSource
}).render();
Upvotes: 0
Views: 373
Reputation: 291
You need to set the date time format correctly based on the date time you are passing.
Check the following correct date-time format in your schema.
const schema = [{"name":"Date","type":"date","format":"%Y-%m-%d"},{"name":"Value","type":"number"}]
Also check the following modified sample http://jsfiddle.net/t7y3upoj/1/
Upvotes: 2