Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Q&A How do I install Chart.js as a file?

I'm trying to replace Flot.js with Chart.js. In my application, Flot.js is included as a normal JavaScript file, like so: <script language="javascript" type="text/javascript" src="jquery.flot-...

1 answer  ·  posted 7mo ago by CavanWright‭  ·  last activity 7mo ago by Ullallulloo‭

Question chart.js
#1: Initial revision by user avatar CavanWright‭ · 2023-10-04T18:06:32Z (7 months ago)
How do I install Chart.js as a file?
I'm trying to replace Flot.js with Chart.js.  In my application, Flot.js is included as a normal JavaScript file, like so:
```
<script language="javascript" type="text/javascript" src="jquery.flot-0.8.3.js"></script>
```
I'm looking for a way to do the same for Chart.js.

The [releases](https://github.com/chartjs/Chart.js/releases/tag/v4.4.0) section of the Chart.js GitHub page has packages available for download.  From its v4.4.0 `.tgz` package, for example, I found the `package/dist/chart.js` file and included it in my application.  After doing so, the console reports the error 

> Uncaught SyntaxError: import declarations may only appear at top level of a module chart.js:7:1

(In fact, the very first non-comment line of `chart.js` is an import statement:
```
/*!
 * Chart.js v4.4.0
 * https://www.chartjs.org
 * (c) 2023 Chart.js Contributors
 * Released under the MIT License
 */
import { r as requestAnimFrame, a as resolve, e as effects, c as color, i as isObject, d as defaults, b as isArray, v as valueOrDefault, u as unlistenArrayEvents, l as listenArrayEvents, f as resolveObjectKey, ...
```
so I'm not certain what to make of this error.  Is `chart.js` not the top level of the `chart.js` module?  If not, what is?)

In addition, when I insert the "Hello world" example given in the [Chart.js docs](https://www.chartjs.org/docs/latest/getting-started/), no chart is created on the page and the console additionally reports the error

> Uncaught ReferenceError: Chart is not defined

I found similar files available via a [CDN page](https://cdnjs.com/libraries/Chart.js).  These files appear to be equivalent in content to the package files from the Chart.js GitHub, and when I include them in my application I get the same result.

I have found similar questions on Stack Overflow [here](https://stackoverflow.com/a/43959072/6673905), where the only useful answer doesn't provide any more detail than what I've already tried, and [here](https://stackoverflow.com/q/41191713/6673905), where the only answer is to use the CDN, which is not what I'm looking for.

Is there a way to incorporate Chart.js as a first-party file?