Learn Chart.js

Book description

Design interactive graphics and visuals for your data-driven applications using the popular open-source Chart.js data visualization library.

Key Features

  • Harness the power of JavaScript, HTML, and CSS to create interactive visualizations
  • Display quantitative information efficiently in the form of attractive charts by using Chart.js
  • A practical guide for creating data-driven applications using open-source JavaScript library

Book Description

Chart.js is a free, open-source data visualization library, maintained by an active community of developers in GitHub, where it rates as the second most popular data visualization library. If you want to quickly create responsive Web-based data visualizations for the Web, Chart.js is a great choice.

This book guides the reader through dozens of practical examples, complete with code you can run and modify as you wish. It is a practical hands-on introduction to Chart.js. If you have basic knowledge of HTML, CSS and JavaScript you can learn to create beautiful interactive Web Canvas-based visualizations for your data using Chart.js. This book will help you set up Chart.js in a Web page and show how to create each one of the eight Chart.js chart types. You will also learn how to configure most properties that override Chart's default styles and behaviors. Practical applications of Chart.js are exemplified using real data files obtained from public data portals. You will learn how to load, parse, filter and select the data you wish to display from those files. You will also learn how to create visualizations that reveal patterns in the data. This book is based on Chart.js version 2.7.3 and ES2015 JavaScript.

By the end of the book, you will be able to create beautiful, efficient and interactive data visualizations for the Web using Chart.js.

What you will learn

  • Learn how to create interactive and responsive data visualizations using Chart.js
  • Learn how to create Canvas-based graphics without Canvas programming
  • Create composite charts and configure animated data updates and transitions
  • Efficiently display quantitative information using bar and line charts, scatterplots, and pie charts
  • Learn how to load, parse, and filter external files in JSON and CSV formats
  • Understand the benefits of using a data visualization framework

Who this book is for

The ideal target audience of this book includes web developers and designers, data journalists, data scientists and artists who wish to create interactive data visualizations for the Web. Basic knowledge of HTML, CSS, and JavaScript is required. No Canvas knowledge is necessary.

Publisher resources

View/Submit Errata

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Chart.js
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Introduction
    1. Data visualization
      1. Chart types
      2. Choosing a chart
      3. Web-based visualizations
    2. Why use a data visualization library?
      1. Creating data visualizations for the Web
    3. How to use this book
    4. Summary
    5. References
  7. Technology Fundamentals
    1. Essential JavaScript for Chart.js
      1. Browser tools
      2. JavaScript types and variables
      3. Data structures used in charts
      4. Arrays
      5. Strings
      6. Functions
      7. Objects
    2. Other technologies
      1. HTML Document Object Model(DOM)
      2. Cascading Style Sheets
      3. JQuery fundamentals
      4. HTML5 Canvas
    3. Data formats
      1. CSV
      2. XML
      3. JSON
    4. Loading and parsing external data files  
      1. Using a Web server
      2. Loading files using standard JavaScript
      3. Loading files using JQuery
      4. Loading files using the standard Fetch API
      5. Parsing JSON
      6. Parsing CSV
      7. Loading multiple files
      8. Displaying a map
    5. Extracting and transforming data
      1. Online tools
      2. Extracting data with XPath
    6. Summary
  8. Chart.js - Quick Start
    1. Introduction to Chart.js
      1. Installation and setup
    2. Creating a simple bar chart
      1. Setting up the graphics context
    3. Creating a bar chart
    4. Configuring colors, fonts, and responsiveness
      1. Dataset configuration for bar charts
    5. Options configuration
      1. Text and fonts
    6. Global defaults
    7. Transitions, interactions, and tooltips
      1. Transition duration
    8. Updating charts
      1. Tooltips
    9. Working with larger and multiple datasets
      1. Loading data
    10. Horizontal bar chart
      1. Adding extra datasets
    11. Stacking bars
    12. Summary 
    13. References
  9. Creating Charts
    1. Line and area charts
      1. Creating a simple line chart
      2. Dataset configuration
      3. Options configuration for line charts
      4. Line charts with more than one dataset
      5. Loading data from external files
    2. Stacked area charts
    3. Radar charts
    4. Pie and doughnut charts
      1. Creating a simple pie chart
      2. Dataset properties for pie charts
      3. Configuration options
      4. How to show values in the slices
      5. Preparing data for pie and doughnut charts
      6. Changing the circumference
      7. Pie and doughnut charts with multiple datasets
    5. Polar area charts
    6. Scatter and bubble charts
      1. Creating a scatter chart
      2. Revealing correlations with scatter charts
      3. Scatter charts with large quantities of data
      4. Bubble charts
    7. Summary
    8. References
  10. Scales and Grid Configuration
    1. Configuring scales
    2. Cartesian configuration options
    3. Cartesian axes, ticks, and grid lines
    4. Numeric Cartesian scales
      1. Linear scales
      2. Logarithmic scales
      3. Configuring axis titles
      4. Configuring ticks
      5. Configuring grid lines
    5. Category scales
      1. Configuring the axes
      2. Configuring ticks
      3. Configuring grid lines
    6. Time scales
      1. Configuring the time format
      2. Configuring the axes
      3. Configuring ticks
      4. Configuring grid lines
    7. Radial scales
      1. Configuring point labels
      2. Configuring ticks
      3. Configuring grids and angle lines
    8. Configuring advanced scales
      1. Multiple Cartesian axes
      2. Callbacks
      3. The scale service
    9. Summary
    10. References
  11. Configuring Styles and Interactivity
    1. Default configuration
      1. Global defaults
      2. Scale defaults
      3. Graphical elements
      4. Chart defaults
    2. Fonts
      1. Selecting standard fonts
      2. Using Web fonts
    3. Colors, gradients, patterns, and shadows
      1. Configuring colors
      2. Color schemes and palettes
    4. Gradients
    5. Patterns
    6. Shadows and bevels
    7. Adding text elements and labels
      1. Legends and labels
    8. Titles
      1. Adding labels to lines, bars, and slices
      2. Interactions, data updates, and animations
      3. Data updates
    9. Events
      1. Configuring animations
    10. Summary
    11. References
  12. Advanced Chart.js
    1. Tooltip configuration
    2. Hovering interactions
    3. Scriptable properties
      1. Tooltip callbacks
    4. Custom HTML tooltips
      1. Advanced legend configuration
      2. Generating labels
    5. HTML legends
    6. Displaying multiple charts
      1. Rendering many charts on one page
    7. Mixed charts
      1. Overlaying a canvas
    8. Extending Chart.js
      1. Prototype methods
    9. Creating plugins
    10. Chart.js extensions
    11. Summary
    12. References
  13. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Learn Chart.js
  • Author(s): Helder da Rocha
  • Release date: February 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789342482