question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import of a single chart type module does not work correctly

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior When importing a single chart type like PieChartModule, the chart common components like tooltips are not working.

Expected behavior <ngx-charts-pie-chart></ngx-charts-pie-chart> should work correctly when importing PieChartModule

Reproduction of the problem https://plnkr.co/edit/5Ct4CiXVId7FRzlg5bG2

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
henriquecustodiacommented, Nov 28, 2018

@juarezpaf Hey there, I had to use a workaround.

Import the chart component:

import { LineChartModule } from '@swimlane/ngx-charts/release/line-chart';

@NgModule({
  imports: [
    LineChartModule
  ]
})

Importing only that module will throw some errors on dev mode (I’ve mentioned here), so I’ve created a simple node script to inline external css from ngx-chart.

const ngInline = require('angular2-inline-template-style');
const path = require('path');
const fse = require('fs-extra');
const glob = require('glob');

const baseDir = path.join(process.cwd(), 'node_modules/@swimlane/ngx-charts/release');

const paths = glob.sync('**/*.js', { cwd: baseDir });

paths.forEach(filepath => {

    const fullpath = path.join(baseDir, filepath);

    fse.readFile(fullpath, { encoding: 'utf8' })
        .then(content => {
            const fileDir = path.dirname(fullpath);

            return ngInline(content, { base: fileDir, compress: true })
                .then(content => {
                    return fse.writeFile(fullpath, content);
                });
        })

});

You have to run the script after the npm install

// package.json
 "scripts": {
        "postinstall": "node scripts/inline-ngx-chart-styles.js"
}

the package angular2-inline-template-style will inline all ngx-charts components

I hope it can useful! 😄

2reactions
eseligercommented, Mar 20, 2018

same here, @Luukschoen I think the modules should work on their own as well, shouldn’t they? There are probably a lot applications that don’t need every type of chart and they are all forced to take the much bigger payload as long as it isn’t working with the separate imports

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chart JS +ng2-charts not working on Angular+2 - Stack Overflow
I was facing the below-mentioned issue with charts. Error: node_modules/ng2-charts/lib/base-chart.directive.d.ts:17:23 - error TS2724: ' ...
Read more >
Integration | Chart.js
Chart.js is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use. # ......
Read more >
Module Methods - webpack
This section covers all methods available in code compiled with webpack. When using webpack to bundle your application, you can pick from a...
Read more >
JavaScript modules - MDN Web Docs
Use of native JavaScript modules is dependent on the import and ... Most servers already set the correct type for .js files, but...
Read more >
Using TypeScript or ES6 – amCharts 4 Documentation
This must be put before everything else, or it won't work! ... Each chart-specific module will contain all classes that specific chart type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found