Error Message: Chartist Undefined Exception

Recently, I've been experimenting with the Chartist.js framework in an attempt to incorporate charts and graphs into my website. However, I seem to be encountering a persistent issue that keeps popping up as "Chartist is not defined."

No matter how hard I try, I can't seem to figure out how to resolve this error. Below is a snippet of the code that seems to be causing the problem:

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
    <link href="https//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css" rel="stylesheet" type="text/css" />
    <link href='http://fonts.googleapis.com/css?family=Oxygen:300' rel='stylesheet' type='text/css'>
    <meta charset="utf-8">
    <title>Chartist.js - Simple line chart</title>
    <script>
       // THIS IS WHERE THE ERROR OCCURS
       new Chartist.Line('.ct-chart', {
       labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
       series: [
                 [2, 3, 2, 4, 5],
                 [0, 2.5, 3, 2, 3],
                 [1, 2, 2.5, 3.5, 4]
               ]
        }, {
          width: 500,
          height: 300
       });

     </script>
     </head>

     <body>
     <div class="ct-chart"></div>

     </body>
     </html>

Can anyone shed some light on what could possibly be going wrong here? Appreciate any assistance in advance.

Answer №1

Relocate your scripts to the footer for better performance:

<!DOCTYPE html>
<html>
<head>

    <link href="https//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css" rel="stylesheet" type="text/css" />
    <link href='http://fonts.googleapis.com/css?family=Oxygen:300' rel='stylesheet' type='text/css'>
    <meta charset="utf-8">
    <title>Chartist.js - Simple line chart</title>

     </head>

     <body>
     <div class="ct-chart"></div>
    <script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
    <script>
       // THE ISSUE ARISES HERE
       new Chartist.Line('.ct-chart', {
       labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
       series: [
                 [2, 3, 2, 4, 5],
                 [0, 2.5, 3, 2, 3],
                 [1, 2, 2.5, 3.5, 4]
               ]
        }, {
          width: 500,
          height: 300
       });

     </script>
     </body>

     </html>

http://plnkr.co/edit/3sAdiBJaaue3x9kgBRZw?p=preview

This adjustment has significantly improved performance :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the maximum size limit for serializing data with ipCookie()?

Utilizing the angular-cookie library, which can be found here, I have encountered an issue. The documentation on this page mentions: To create a cookie use ipCookie(key, value); The value supports strings, numbers, booleans, arrays and objects and will b ...

Is there a way to launch an ajax request in a distinct frame?

So, I've come across this code snippet: <script language="javascript" type="text/javascript"> <!-- function loadContent(page) { var request = false; try { request = new XMLHttpRequest(); } catch (e) { try{ ...

There was an issue with loading ngCookies into the Web Application

I have been attempting to add a 'remember me' feature to my login page by using ngCookies to store a local cookie. Despite following the instructions from the angular documentation, I am encountering issues with getting the module to function pro ...

A space designated for numerous receivers

Is there a way to create a field that contains other elements, similar to sending messages to multiple users in a social network? https://i.stack.imgur.com/P9e24.png I attempted to understand the code for this, but it's quite complex. If anyone could ...

Vee Verify managing input rows that adapt to change

I am currently facing an issue while trying to validate dynamically added input fields. When there is only one row of inputs for validation, everything works as expected. When it works: https://i.sstatic.net/nNesg.png However, the problem arises when I a ...

My attempt to reveal hidden information in my repeater using a button and JavaScript has not produced the desired results

Welcome to my first post on this forum. In the HTML code, there is a repeater containing a button shown below: <button type="button" class="btn btn-info">Contact</button> <p style="display: none" id="contact"><%# Eval("Email") %&g ...

What is the best way to loop through this JSON object without using jQuery?

I have a json object that I obtained using var jsonObj = json_encode( <?php echo $php_array ?>);. It looks different from the typical format, such as what is shown on w3schools: { "employees": [ { "firstName":"John" , "lastName":"Doe" }, ...

AngularJS applies the active class to the button within a button group

Currently, I am facing an issue with a button group that consists of buttons, some created using HTML and others generated through ng-repeat. The goal is to have an active class applied to the button when clicked so that it can be customized to indicate th ...

Is there a way to design a CSS layout that automatically adjusts text wrapping based on the size of the page and columns?

I am attempting to design a CSS page that mimics the appearance of an aged newspaper. The focus is on ensuring that the page is responsive, with a single column of text on smaller devices. However, the main issue I need help with lies elsewhere. For larg ...

Automatically closing jQuery UI Dialog with setTimeout Function

My goal is to automatically close a dialog three seconds after it opens. I have tried various methods but encountered some issues: setTimeout($("#mydialog").dialog('close'), 3000); Here is the code snippet in context: $("#acknowledged-dialog") ...

Dynamically update Angular directives with a new template

One of the controllers I created has some variables: .controller('DataProvider', function($scope, $timeout, $mdSidenav, $mdDialog, $mdMedia, $mdToast, selectedData) { $scope.provider; $scope.providers = [{ name: 'jsonProvide ...

What is the best way to transfer information from jQuery to HTML?

Currently, I have a separate script written in jQuery that retrieves data from an API. function sendRequest() { $.ajax({ url: "http://localhost:3002/api/people", type: "get", //using get method data: { ...

Performing a consistent influx of data into a MySQL database using Node.js encounters an issue: "Unable to enqueue Handshake as a Handshake has

I am trying to insert values into a database in a continuous manner. Here is the code I have attempted: var mysql = require("mysql"); const random = require("random"); var con = mysql.createConnection({ host: "xxx", user: "xxx", password: "xxx", ...

Implementing socket.io in a node.js server with express to showcase a welcome message upon user login

Currently, I am in the process of creating a web chat client using socket.io. However, before I can proceed with this project, I need to establish communication between my server and the website on localhost. Despite receiving the 'listening' me ...

Bring in a class using an NPM package that contains several classes

When attempting to import classes from my NPM package in main.js, I encountered an issue. import { Organization, Club } from "sqorz-client"; o = new Organization(); o.setId("id"); c = new Club(); c.setId("anotherid"); The er ...

What is the best way to maintain a font size of 150% even after refreshing the page or reopening it?

After successfully implementing two buttons that allow users to adjust the font size on my webpage, I noticed that upon refreshing or reopening the page, the font size resets to its default setting. How can I ensure that the font size remains at 150% even ...

"Utilize JavaScript for graceful error handling in your project with

I am trying to implement an Ant task that involves adding JavaScript code. I want the success or failure of the target to be determined by the results of some logic executed in the JavaScript: <target name="analyze"> <script language="javas ...

jQuery - How come my string values are getting cut off?

It's been a while since I last worked with jQuery, and I seem to be missing something obvious that's affecting my calculations. I have various text boxes for Weight, Moisture %, and Number of Filled Squares, as well as a multi-select option for ...

Troubleshooting AngularJS and PHP for cross-origin resource sharing (CORS

I am encountering a problem while attempting to execute an $http call to my REST PHP server. The calls are being made across different domains, from the client to the backend. Here is how the $http service is configured within my Angular application: .co ...

Navigate in AngularJS with ui-router by using href instead of ui-sref for a more dynamic and efficient user experience

Is there a method to prompt the ui-router to access a link based on its "href" attribute? For instance, I have an anchor tag: <a href="#mystate/89/10/items" ui-sref="my.category.subcategory.items({sub_category_id: 10})">Link</a>. Upon clickin ...