Skip to content

Commit 521580e

Browse files
committed
added the timeseries example
1 parent f8e6f68 commit 521580e

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<html>
2+
<head>
3+
<style>
4+
#container {
5+
width: 1200px;
6+
height: 400px;
7+
}
8+
</style>
9+
</head>
10+
<body>
11+
<div id="container"></div>
12+
<script>
13+
function fetchCheckStatus(response) {
14+
if (response.status >= 200 && response.status < 300) {
15+
return response;
16+
}
17+
const error = new Error(response.statusText);
18+
error.response = response;
19+
throw error;
20+
}
21+
22+
function loadData(url) {
23+
const option = {
24+
method: "GET",
25+
headers: new Headers(),
26+
mode: "cors",
27+
cache: "default"
28+
};
29+
30+
return fetch(url, option)
31+
.then(fetchCheckStatus)
32+
.then(resp => {
33+
const contentType = resp.headers.get("Content-Type");
34+
if (contentType && contentType.indexOf("application/json") !== -1) {
35+
return resp.json();
36+
}
37+
return resp.text();
38+
})
39+
.then(data => data)
40+
.catch(() => {
41+
console.log("Something went wrong! Please check data/schema files");
42+
});
43+
}
44+
45+
Promise.all([
46+
loadData(
47+
"https://s3.eu-central-1.amazonaws.com/fusion.store/ft/data/line-chart-with-time-axis-data.json"
48+
),
49+
loadData(
50+
"https://s3.eu-central-1.amazonaws.com/fusion.store/ft/schema/line-chart-with-time-axis-schema.json"
51+
)
52+
]).then(res => {
53+
const data = res[0];
54+
const schema = res[1];
55+
56+
const dataStore = new FusionCharts.DataStore(data, schema);
57+
58+
new FusionCharts({
59+
type: "timeseries",
60+
renderAt: "container",
61+
width: "100%",
62+
height: "100%",
63+
dataSource: {
64+
// Initially data is set as null
65+
caption: {
66+
text: "Sales Analysis"
67+
},
68+
subcaption: {
69+
text: "Grocery"
70+
},
71+
yAxis: [
72+
{
73+
plot: {
74+
value: "Grocery Sales Value",
75+
type: "line"
76+
},
77+
format: {
78+
prefix: "$"
79+
},
80+
title: "Sale Value"
81+
}
82+
],
83+
data: dataStore.getDataTable()
84+
}
85+
}).render();
86+
});
87+
</script>
88+
</body>
89+
</html>

example/time_series.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('path');
2+
3+
// Require FusionExport
4+
const { ExportManager, ExportConfig } = require('../');
5+
6+
// Instantiate ExportManager
7+
const exportManager = new ExportManager();
8+
9+
// Instantiate ExportConfig and add the required configurations
10+
const exportConfig = new ExportConfig();
11+
12+
exportConfig.set('templateFilePath', path.join(__dirname, 'resources', 'template_timeseries.html'));
13+
exportConfig.set('type', 'jpg');
14+
exportConfig.set('asyncCapture', true);
15+
exportConfig.set('maxWaitForCaptureExit', 10000);
16+
17+
// provide the export config
18+
exportManager.export(exportConfig, '.', true).then((exportedFiles) => {
19+
exportedFiles.forEach(file => console.log(file));
20+
}).catch((err) => {
21+
console.log(err);
22+
});

0 commit comments

Comments
 (0)