Open kavimaluskam opened 7 years ago
What does your index.ejs
look like? Does it have the script tags like step 3 in the README or the webpack examples? That's the supported method of loading AmCharts with the latest version of this.
I had tried using both index.ejs
with <script>
tags and the webpack import at the same time but it does not work.
Yet i think import AmCharts from "@amcharts/amchart3-react";
in my chart.js, which is the chart component alone is sufficiency enough for loading the amcharts module?
It actually is not with the version in your package.json. With 2.x, you can see that the index.js does not load the amcharts module like in the latest 1.x version.
You need to add this to your html file. Otherwise, it will throw errors. Usually you dont have to do this if you are using webpack but for this library it requires this thing
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
How did you solve the issue? I'm facing the same problem using gulp. I am using script tags and the import at the same time.
is it possible to load the online imports into the project?
Online imports must be in the package, for some clients we are not allowed to get content from the CDN.
The react package must be standalone, installing all of its dependencies locally.
A workaround could be to also npm i amcharts/amcharts3
(the base library) and then import the relevant files from there:
import 'amcharts3/amcharts/amcharts';
import 'amcharts3/amcharts/serial';
import 'amcharts3/amcharts/themes/light';
I still get a pre-render error complaining that AmCharts is not defined, but eventually it renders and can see the library being loaded correctly. This is not pretty, though, and I think some better examples of how to use amcharts with React and NPM specifically could be worked out.
If you are distributing over NPM then using a CDN to load the base library is not a solution and defeats the whole purpose of having a dependency manager manage your dependencies.
You can work around most but I couldn't figure out a clean way to import the export
functionality. Since it has tons of dependencies, it fails.
can you plz fix that. I haven't found a way to include them without errors. I can't use it, if it's not standalone :/
@jeffsrepoaccount This is what I am currently doing in my project to import them and I am not getting an error.
import 'amcharts3';
import 'amcharts3/amcharts/serial';
import AmCharts from '@amcharts/amcharts3-react';
@cemremengu That isn't possible, because the AmCharts export plugin dynamically loads files at runtime, which is why you must use <script>
tags.
If you do not want to use our CDN, you can download AmCharts, put the AmCharts files on your server, then use <script>
tags which use the AmCharts files on your server.
@jeffsrepoaccount @freakaziod210 That won't work if you use the export plugin.
We agree that being able to use npm + webpack to manage everything is a good thing.
But AmCharts v3 was made many many years ago, before npm or webpack even existed.
Because of that, AmCharts v3 is designed to work with <script>
tags, and it is too difficult for us to make it work with npm.
However, we are actively working on AmCharts v4. It is not finished yet, but when it is released it will have full support for npm + webpack.
script
We npm install amcharts/amcharts3
then use dynamic import, this way we achieve encapsulation and code split. Promise.all([ //dynamically import amchart dependencies import('amcharts3/amcharts/amcharts'), import('amcharts3/amcharts/serial'), import('amcharts3/amcharts/themes/light') ]).then(() => { //amChart config });
I went ahead and added the 3 script calls, and the charts work in the app, but when i use Jest to test things, i still get this message.
any help/ideas are appreciated...
Same problem here @runn-vermel ...
Did you manage to find a solution?
Nope - I commented stuff out, and will likely upgrade to a different library. Sorry I'm not more help :(
On Mon, Jan 29, 2018 at 01:51 HarryFaulkner notifications@github.com wrote:
Same problem here @runn-vermel https://github.com/runn-vermel ...
Did you manage to find a solution?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/amcharts/amcharts3-react/issues/51#issuecomment-361193150, or mute the thread https://github.com/notifications/unsubscribe-auth/AEGM8fgLpwYNiAEBUx8De_5qKkd4EHh-ks5tPZSOgaJpZM4OHZwI .
at least you have load this files
then you can use this library in react
....
I would just like to point out that we have released V4, which has excellent built-in support for npm/Webpack/React:
https://www.amcharts.com/javascript-charts/ https://www.amcharts.com/docs/v4/getting-started/integrations/using-react/
We will still support V3 for a while, but our effort is primarily going into V4.
I just failed to import AmCharts with guidelines from the tutorial.
Below are my files:
chart.js
package.json
webpack.config.js