Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to make it work with NodeJS and ChartjsNodeCanvas #78

Open
vzhilov opened this issue Aug 14, 2020 · 5 comments
Open

Trying to make it work with NodeJS and ChartjsNodeCanvas #78

vzhilov opened this issue Aug 14, 2020 · 5 comments

Comments

@vzhilov
Copy link

vzhilov commented Aug 14, 2020

Hello, thank you for the great plugin!

I do:

Git clone https://github.com/chartjs/chartjs-chart-financial/
cd chartjs-chart-financial
npm install
gulp build

As result I get a file in /dist directory and copy it to me NodeJS project folder.

In my NodeJS app I do:

const Chart = require(‘chart.js’)
const ChartFinancial = require(‘./chartjs-chart-financial.js’)

When I run the app I get:

chartjs-chart-financial.js:227
globalOpts.elements.financial = {
TypeError: Cannot set property ‘financial’ of undefined

I have checked content of Chart.defaults and found that .elements is in ‘global’ so I changed

225 const globalOpts = Chart.defaults.global
316 const globalOpts$1 = Chart.defaults.global
401 const globalOpts$2 = Chart.defaults.global

And eventually Error

Chart.defaults.set(‘ohlc’ ... 

on line 446

So I changed them to:

446 Chart.defaults.ohlc.datasets.barPercentage = 1.0,
447 Chart.defaults.ohlc.datasets.categoryPercentage = 1.0

Then I got

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
at CandlestickController.draw (C:\inetpub\github\telegram-stream-trades\chartjs-chart-financial.js:213:32)

So I chagned:

213 const rects = me.getMeta();

That handled all the errors. But still no candles drawn.

So probably the way I initially started is incorrect

@vzhilov vzhilov changed the title Trying to make it work with NodeJS Trying to make it work with NodeJS and ChartjsNodeCanvas Aug 16, 2020
@benmccann
Copy link
Collaborator

This project requires Chart.js 3.0. I wonder if you're using Chart.js 2.x?

@vzhilov
Copy link
Author

vzhilov commented Nov 4, 2020

Chart.js 3.0 is just only a beta issued just 3 days ago. You mean the upgrade will fix it?

@benmccann
Copy link
Collaborator

"chart.js": "^3.0.0-beta.3",

@vzhilov
Copy link
Author

vzhilov commented Nov 4, 2020

I see, thank you very much.

v3.0.0-beta.4
Breaking Changes
#7886 Shorten alignment settings for axes
#7871 Polar Area elements.arc.angle option now returns degrees
#7843 Provide method to lookup a chart from a canvas
#7833 Enable per-dataset circumference and rotation for pie/doughnut charts

After upgrading to chart.js@3.0.0-beta.5

git clone https://github.com/chartjs/chartjs-chart-financial
cd chartjs-chart-financial
npm install
gulp build

take built file from /dist, copy to my project and then:

const chartJsFactory = () => {
        require('./dist/chartjs-chart-financial.js');
        delete require.cache[require.resolve('chart.js')];
        delete require.cache[require.resolve('./dist/chartjs-chart-financial.js')];
        return Chart;
    }

const canvasRenderService = new CanvasRenderService(width, height, undefined, undefined, chartJsFactory);

(node:6428) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at afterBuildTicks (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\dist\chartjs-chart-financial.js:154:22)
at callback (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:305:15)
at CategoryScale.afterBuildTicks (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:5112:5)
at CategoryScale.update (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:5035:8)
at fitBoxes (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:1538:9)
at Object.update (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:1654:9)
at Chart._updateLayout (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:6733:13)
at Chart.update (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:6715:8)
at new Chart (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chart.js\dist\chart.js:6477:10)
at CanvasRenderService.renderChart (C:\inetpub\wwwroot\streamtrades.ru\telegram-stream-trades\node_modules\chartjs-node-canvas\dist\index.js:151:16)

@reynard80
Copy link

Same problem here:
(node:6428) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined

I guess no solution is available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants