Skip to content

Commit 1463a95

Browse files
committed
Update route, use anychart.fromJson
1 parent d232377 commit 1463a95

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

routes/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ var Fruit = require('../models/Fruit.js');
66
router.get('/', function(req, res, next) {
77
Fruit.find({}).select('name value -_id').sort({'value': -1}).limit(5).exec(function (err, fruits) {
88
if (err) return next(err);
9-
res.render('index', {title: 'Anychart NodeJS demo',
10-
chartTitle: "Top 5 fruits",
11-
chartData: JSON.stringify(fruits)
12-
});
9+
// chart JSON data
10+
var json = {
11+
chart: {
12+
type: "pie",
13+
title: 'Top 5 Fruits',
14+
data: fruits,
15+
container: "container"
16+
}
17+
};
18+
res.render('index', {title: 'Anychart NodeJS demo', chartData: JSON.stringify(json)});
1319
});
1420
});
1521

views/index.jade

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ block content
44
div(id="container")
55
script.
66
anychart.onDocumentReady(function () {
7-
var chart = anychart.pie(!{chartData});
8-
chart.title("#{chartTitle}");
9-
chart.container("container");
7+
var chart = anychart.fromJson(!{chartData});
108
chart.draw();
119
});

0 commit comments

Comments
 (0)