Server side support for DC.js. Renders graphs using jsdom.
dc = require('dc-node');
Server side support for DC.js
License: Apache License 2.0
Good day I have the following code to try to render a Bar Chart from Node.js using Express Framework and JSDOM:
var express = require('express');
var router = express.Router();
var d3 = require('d3');
var d3request = require('d3-request');
var jsdom = require('jsdom');
global.d3_document = jsdom.jsdom();
var dc = require('dc');
/* GET bar for specific dataframe with given dimensions. */
router.get('/:dftitle/:xdim/:ydim/', function(req, res, next) {
/* Use d3-request to get the data */
d3request.tsv("http://localhost:3000/data/data.tsv", function(d){
d.pay = +d.pay;
d.bal = +d.bal;
return d;
}, function(data){
const containerSelector = 'bar-chart-container';
var htmlStub = '<html><head>Hello</head><body><div id="'+containerSelector+'"></div></body></html>';
//Render the Chart
jsdom.env({ features : { QuerySelector : true }, html : htmlStub
, done : function(errors, window) {
bcc = window.document.querySelector(containerSelector);
global.d3_document = window.document;
var BarChart = dc.barChart(bcc);
console.log(BarChart);
res.send(jsdom.serializeDocument(window.document));
}
});
});
});
module.exports = router;
Its failing exactly at var BarChart = dc.barChart(bcc);
with the error:
/usr/local/src/node/s3d3c/node_modules/d3/d3.js:1312
d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
^
TypeError: Cannot use 'in' operator to search for 'onwheel' in undefined
at Object.d3.behavior.zoom (/usr/local/src/node/s3d3c/node_modules/d3/d3.js:1312:44)
at Object.dc.coordinateGridMixin (/usr/local/src/node/s3d3c/node_modules/dc/dc.js:2760:29)
at Object.dc.barChart (/usr/local/src/node/s3d3c/node_modules/dc/dc.js:5277:35)
at Object.jsdom.env.done (/usr/local/src/node/s3d3c/routes/bars.js:25:27)
at /usr/local/src/node/s3d3c/node_modules/jsdom/lib/jsdom.js:275:18
at nextTickCallbackWith0Args (node.js:453:9)
at process._tickCallback (node.js:382:13)
Is it possible for this chart to be rendered server side using JSDOM? How does this library work? Can you help me out please?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.