Logo Logo v2.1
Image Description Image Description

No Results

  • Get Support
  • Preview Demo
Logo Logo v2.1.1
  • Documentation
  • Introduction
  • Getting started
  • Getting Started
  • Gulp
  • Dark Mode New
  • Customization
  • Credits
  • Changelog
  • Design & Graphics
  • Bootstrap Icons
  • Illustrations
  • Components
  • Accordion
  • Alerts
  • Avatars
  • Badge
  • Breadcrumb
  • Buttons
  • Button Group
  • Cards
  • Collapse
  • Column Divider
  • Devices
  • Divider
  • Dropdowns
  • Icons
  • List Group
  • Lists
  • Legend Indicator
  • Modal
  • Offcanvas
  • Page Header
  • Pagination
  • Popovers
  • Progress
  • Profile
  • Shapes
  • Sliding Image
  • Spinners
  • Steps
  • Tab
  • Toasts
  • Tooltips
  • Typography
  • Navbars
  • Navbar
  • Navs
  • Mega Menu
  • Navbar Vertical Aside
  • Scrollspy
  • Tables
  • Tables
  • Datatables
  • Sticky Header
  • Basic forms
  • Basic Forms
  • Checks & Switches
  • Input Group
  • Advanced Forms
  • Advanced Select
  • Datepicker (Flatpickr)
  • Date Range Picker
  • Calendar (Fullcalendar)
  • File Attachments
  • Drag’ n’ Drop File Uploads
  • WYSIWYG Editor
  • Quantity Counter
  • Copy to Clipboard
  • Input Mask
  • Step Forms (Wizards)
  • Add Field
  • Toggle Password
  • Count Characters
  • Form Search
  • Toggle Switch
  • Google reCAPTCHA
  • Charts
  • Chart.js
  • Counter
  • Circles.js (Pie Chart)
  • Others
  • Fullscreen Lightbox
  • Leaflet
  • JSVectorMap
  • SortableJS
  • Sticky Block
  • Go To
  • Utilities
  • Backgrounds
  • Borders
  • Colors
  • Links
  • Position
  • Shadows
  • Sizing
  • Spacing
  • Z-index
  • Opacity

Chart.js

Simple yet flexible JavaScript charting for designers & developers.

Chart.js documentation

How to use

Copy-paste the following <script> near the end of your pages under JS Implementing Plugins to enable it.

        
          <script src="./node_modules/chart.js/dist/Chart.min.js"></script>
        
      

Copy-paste the following <script> near the end of your pages under JS Implementing Plugins to enable it.

        
          <script src="./assets/js/hs.chartjs.js"></script>
        
      

Copy-paste the init function under JS Plugins Init., before the closing </body> tag, to enable it.

        
          <script>
            (function() {
              // INITIALIZATION OF CHARTJS
              // =======================================================
              document.querySelectorAll('.js-chart').forEach(item => {
                HSCore.components.HSChartJS.init(item)
              })
            })();
          </script>
        
      

Line chart

  • Preview
  • HTML
$7,431.14 USD
Income
Expenses
              
                <div class="row align-items-sm-center mb-4">
              <div class="col-sm mb-3 mb-sm-0">
                <div class="d-flex align-items-center">
                  <span class="h1 mb-0">$7,431.14 USD</span>
                </div>
              </div>

              <div class="col-sm-auto">
                <!-- Legend Indicators -->
                <div class="row font-size-sm">
                  <div class="col-auto">
                    <span class="legend-indicator bg-primary"></span> Income
                  </div>
                  <div class="col-auto">
                    <span class="legend-indicator bg-info"></span> Expenses
                  </div>
                </div>
                <!-- End Legend Indicators -->
              </div>
            </div>

            <!-- Line Chart -->
            <div class="chartjs-custom" style="height: 18rem;">
              <canvas id="project" class="js-chart"
                      data-hs-chartjs-options='{
                              "type": "line",
                              "data": {
                                 "labels": ["Feb","Jan","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
                                 "datasets": [{
                                  "data": [18,51,60,38,88,50,40,52,88,80,60,70],
                                  "backgroundColor": "transparent",
                                  "borderColor": "#377dff",
                                  "borderWidth": 2,
                                  "pointRadius": 0,
                                  "hoverBorderColor": "#377dff",
                                  "pointBackgroundColor": "#377dff",
                                  "pointBorderColor": "#fff",
                                  "pointHoverRadius": 0,
                                  "tension": 0.4
                                },
                                {
                                  "data": [27,38,60,77,40,50,49,29,42,27,42,50],
                                  "backgroundColor": "transparent",
                                  "borderColor": "#00c9db",
                                  "borderWidth": 2,
                                  "pointRadius": 0,
                                  "hoverBorderColor": "#00c9db",
                                  "pointBackgroundColor": "#00c9db",
                                  "pointBorderColor": "#fff",
                                  "pointHoverRadius": 0,
                                  "tension": 0.4
                                }]
                              },
                              "options": {
                                 "scales": {
                                    "y": {
                                      "grid": {
                                        "color": "#e7eaf3",
                                        "drawBorder": false,
                                        "zeroLineColor": "#e7eaf3"
                                      },
                                      "ticks": {
                                        "min": 0,
                                        "max": 100,
                                        "stepSize": 20,
                                        "color": "#97a4af",
                                        "font": {
                                          "family": "Open Sans, sans-serif"
                                        },
                                        "padding": 10,
                                        "postfix": "k"
                                      }
                                    },
                                    "x": {
                                      "grid": {
                                        "display": false,
                                        "drawBorder": false
                                      },
                                      "ticks": {
                                        "color": "#97a4af",
                                        "font": {
                                          "size": 12,
                                          "family": "Open Sans, sans-serif"
                                        },
                                        "padding": 5
                                      }
                                    }
                                },
                                "plugins": {
                                  "tooltip": {
                                    "prefix": "$",
                                    "postfix": "k",
                                    "hasIndicator": true,
                                    "mode": "index",
                                    "intersect": false,
                                    "lineMode": true,
                                    "lineWithLineColor": "rgba(19, 33, 68, 0.075)"
                                  }
                                },
                                "hover": {
                                  "mode": "nearest",
                                  "intersect": true
                                }
                              }
                            }'>
              </canvas>
            </div>
            <!-- End Line Chart -->
              
            

Updating line chart

Use "gradientPosition": {"x0": 0, "y0": 0, "x1": 0, "y1": 200} to set position for gradient.

  • Preview
  • HTML
  • JS
$7,431.14 USD
  • This week
  • Last week
              
                <div class="row align-items-sm-center mb-4">
              <div class="col-sm mb-3 mb-sm-0">
                <div class="d-flex align-items-center">
                  <span class="h1 mb-0">$7,431.14 USD</span>
                </div>
              </div>

              <div class="col-sm-auto">
                <!-- Nav -->
                <ul class="nav nav-segment" id="projectsTab" role="tablist">
                  <li class="nav-item" data-toggle="chart" data-datasets="0" data-trigger="click" data-action="toggle">
                    <a class="nav-link active" href="javascript:;" data-bs-toggle="tab">
                      <span class="legend-indicator bg-primary"></span> This week
                    </a>
                  </li>
                  <li class="nav-item" data-toggle="chart" data-datasets="1" data-trigger="click" data-action="toggle">
                    <a class="nav-link" href="javascript:;" data-bs-toggle="tab">
                      <span class="legend-indicator bg-info"></span> Last week
                    </a>
                  </li>
                </ul>
                <!-- End Nav -->
              </div>
            </div>

            <!-- Line Chart -->
            <div class="chartjs-custom" style="height: 18rem;">
              <canvas id="updatingLineChart"
                      data-hs-chartjs-options='{
                              "type": "line",
                              "data": {
                                 "labels": ["Feb","Jan","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
                                 "datasets": [{
                                  "backgroundColor": ["rgba(55, 125, 255, .5)", "rgba(255, 255, 255, .2)"],
                                  "borderColor": "#377dff",
                                  "borderWidth": 2,
                                  "pointRadius": 0,
                                  "hoverBorderColor": "#377dff",
                                  "pointBackgroundColor": "#377dff",
                                  "pointBorderColor": "#fff",
                                  "pointHoverRadius": 0,
                                  "tension": 0.4
                                },
                                {
                                  "backgroundColor": ["rgba(0, 201, 219, .5)", "rgba(255, 255, 255, .2)"],
                                  "borderColor": "#00c9db",
                                  "borderWidth": 2,
                                  "pointRadius": 0,
                                  "hoverBorderColor": "#00c9db",
                                  "pointBackgroundColor": "#00c9db",
                                  "pointBorderColor": "#fff",
                                  "pointHoverRadius": 0,
                                  "tension": 0.4
                                }]
                              },
                              "options": {
                                "gradientPosition": {"y1": 200},
                                 "scales": {
                                    "y": {
                                      "grid": {
                                        "color": "#e7eaf3",
                                        "drawBorder": false,
                                        "zeroLineColor": "#e7eaf3"
                                      },
                                      "ticks": {
                                        "min": 0,
                                        "max": 100,
                                        "stepSize": 20,
                                        "color": "#97a4af",
                                        "font": {
                                          "family": "Open Sans, sans-serif"
                                        },
                                        "padding": 10,
                                        "postfix": "k"
                                      }
                                    },
                                    "x": {
                                      "grid": {
                                        "display": false,
                                        "drawBorder": false
                                      },
                                      "ticks": {
                                        "color": "#97a4af",
                                        "font": {
                                          "size": 12,
                                          "family": "Open Sans, sans-serif"
                                        },
                                        "padding": 5
                                      }
                                    }
                                },
                                "plugins": {
                                  "tooltip": {
                                    "prefix": "$",
                                    "postfix": "k",
                                    "hasIndicator": true,
                                    "mode": "index",
                                    "intersect": false,
                                    "lineMode": true,
                                    "lineWithLineColor": "rgba(19, 33, 68, 0.075)"
                                  }
                                },
                                "hover": {
                                  "mode": "nearest",
                                  "intersect": true
                                }
                              }
                            }'>
              </canvas>
            </div>
            <!-- End Line Chart -->
              
            
              
                <script>
                  (function () {
                    // INITIALIZATION OF UPDATING CHARTJS
                    // =======================================================
                    const updatingChartDatasets = [
                      [
                        [18,51,60,38,88,50,40,52,88,80,60,70],
                        [27,38,60,77,40,50,49,29,42,27,42,50]
                      ],
                      [
                        [77,40,50,49,27,38,60,42,50,29,42,27],
                        [60,38,18,51,88,50,40,52,60,70,88,80]
                      ]
                    ]

                    HSCore.components.HSChartJS.init(document.querySelector('#updatingLineChart'), {
                      data: {
                        datasets: [
                          {
                            data: updatingChartDatasets[0][0]
                          },
                          {
                            data: updatingChartDatasets[0][1]
                          }
                        ]
                      }
                    });

                    const updatingLineChart = HSCore.components.HSChartJS.getItem('updatingLineChart')

                    // Call when tab is clicked
                    document.querySelectorAll('[data-toggle="chart"]').forEach(item => {
                      item.addEventListener('click', e => {
                        let keyDataset = e.currentTarget.getAttribute('data-datasets')

                        // Update datasets for chart
                        updatingLineChart.data.datasets.forEach(function(dataset, key) {
                          dataset.data = updatingChartDatasets[keyDataset][key];
                        })
                        updatingLineChart.update()
                      })
                    })
                  })()
                </script>
              
            

Strong line chart

  • Preview
  • HTML
              
                 <!-- Chartjs -->
            <div class="chartjs-custom" style="height: 18rem;">
              <canvas id="strong-line-chart" class="js-chart"
                      data-hs-chartjs-options='{
                          "type": "line",
                          "data": {
                             "labels": ["6:00 PM","6:00 PM","6:01 PM","6:01 PM","6:02 PM","6:02 PM","6:03 PM","6:03 PM","6:04 PM","6:04 PM","6:05 PM","6:05 PM","6:06 PM","6:06 PM","6:07 PM","6:07 PM","6:08 PM","6:08 PM","6:09 PM","6:09 PM","6:10 PM","6:10 PM","6:11 PM","6:11 PM","6:12 PM","6:12 PM","6:13 PM","6:13 PM","6:14 PM","6:14 PM","6:15 PM","6:15 PM","6:16 PM","6:16 PM","6:17 PM","6:17 PM","6:18 PM","6:18 PM","6:19 PM","6:19 PM","6:20 PM","6:20 PM","6:21 PM","6:21 PM","6:22 PM","6:22 PM","6:23 PM","6:23 PM","6:24 PM","6:24 PM","6:25 PM","6:25 PM","6:26 PM","6:26 PM","6:27 PM","6:27 PM","6:28 PM","6:28 PM","6:29 PM","6:29 PM","6:30 PM","6:30 PM","6:31 PM","6:31 PM","6:32 PM","6:32 PM","6:33 PM","6:33 PM","6:34 PM","6:34 PM","6:35 PM","6:35 PM","6:36 PM","6:36 PM","6:37 PM","6:37 PM","6:38 PM","6:38 PM","6:39 PM","6:39 PM","6:40 PM","6:40 PM","6:41 PM","6:41 PM","6:42 PM","6:42 PM","6:43 PM","6:43 PM","6:44 PM","6:44 PM","6:45 PM","6:45 PM","6:46 PM","6:46 PM","6:47 PM","6:47 PM","6:48 PM","6:48 PM","6:49 PM","6:49 PM","6:50 PM","6:50 PM","6:51 PM","6:51 PM","6:52 PM","6:52 PM","6:53 PM","6:53 PM","6:54 PM","6:54 PM","6:55 PM","6:55 PM","6:56 PM","6:56 PM","6:57 PM","6:57 PM","6:58 PM","6:58 PM","6:59 PM","6:59 PM"],
                             "datasets": [{
                              "data": [8516, 8520, 8547, 8575, 8588, 8604, 8601, 8595, 8617, 8612, 8607, 8632, 8636, 8641, 8638, 8641, 8624, 8633, 8643, 8630, 8646, 8662, 8670, 8667, 8658, 8660, 8657, 8648, 8645, 8647, 8652, 8637, 8647, 8640, 8667, 8658, 8660, 8713, 8703, 8705, 8747, 8620, 8635, 8680, 8675, 8667, 8620, 8645, 8645, 8625, 8635, 8645, 8665, 8660, 8670, 8640, 8650, 8640, 8635, 8645, 8695, 8703, 8705, 8640, 8650, 8640, 8620, 8610, 8640, 8630, 8610, 8620, 8600, 8590, 8610, 8620, 8600, 8610, 8605, 8610, 8660, 8665, 8664, 8640, 8645, 8650, 8610, 8620, 8630, 8670, 8675, 8674, 8660, 8665, 8650, 8610, 8612, 8607, 8632, 8636, 8641, 8638, 8641, 8638, 8641, 8624, 8633, 8643, 8630, 8646, 8662, 8638, 8641, 8624, 8633, 8643, 8630, 8646, 8632, 8636],
                              "backgroundColor": "transparent",
                              "borderColor": "#377dff",
                              "borderWidth": 2,
                              "pointBackgroundColor": "transparent",
                              "pointHoverBackgroundColor": "#377dff",
                              "pointBorderColor": "transparent",
                              "pointHoverBorderColor": "#377dff",
                              "pointRadius": 2,
                              "pointHoverRadius": 2,
                              "tension": 0
                            }]
                          },
                          "options": {
                             "scales": {
                                "y": {
                                  "display": false
                                },
                                "x": {
                                  "grid": {
                                    "display": false,
                                    "drawBorder": false
                                  },
                                  "ticks": {
                                    "labelOffset": 40,
                                    "maxTicksLimit": 6,
                                    "padding": 20,
                                    "maxRotation": 0,
                                    "minRotation": 0,
                                    "fontSize": 12,
                                    "fontColor": "rgba(0, 0, 0, 0.4)"
                                  }
                                }
                             },
                            "hover": {
                               "mode": "nearest",
                               "intersect": false
                             },
                            "plugins": {
                              "tooltip": {
                                "prefix": "$",
                                "intersect": false
                              }
                            }
                          }
                        }'>
              </canvas>
            </div>
            <!-- End Chartjs -->
              
            

Line chart with grid

  • Preview
  • HTML
Income
Expenses
              
                 <!-- Legend Indicators -->
            <div class="row justify-content-end mb-5">
              <div class="col-auto">
                <span class="legend-indicator bg-primary"></span> Income
              </div>
              <div class="col-auto">
                <span class="legend-indicator"></span> Expenses
              </div>
            </div>
            <!-- End Legend Indicators -->

            <!-- Chartjs -->
            <div class="chartjs-custom" style="height: 300px;">
              <canvas id="line-chart-with-grid" class="js-chart"
                      data-hs-chartjs-options='{
                          "type": "line",
                          "data": {
                             "labels": ["1AM","2AM","3AM","4AM","5AM","6AM","7AM","8AM","9AM","10AM","11AM","12AM","1PM","2PM","3PM","4PM","5PM","6PM","7PM","8PM","9PM","10PM","11PM","12PM"],
                             "datasets": [{
                              "data": [30,30,30,32,33,34,35,34,33,32,31,30,30,30,30,32,33,34,35,34,33,32,31,30],
                              "backgroundColor": "transparent",
                              "borderColor": "#eeeef1",
                              "borderWidth": 2,
                              "pointRadius": 0,
                              "pointHoverRadius": 1,
                              "tension": 0,
                              "borderDash": [10,5]
                            },
                            {
                              "data": [70,52,47,58,38,40,57,40,31,53,60,43,70,52,47,58,38,40,57,40,31,53,60,43],
                              "backgroundColor": "transparent",
                              "borderColor": "#377dff",
                              "borderWidth": 2,
                              "pointRadius": 0,
                              "pointHoverRadius": 1,
                              "tension": 0
                            }]
                          },
                          "options": {
                             "scales": {
                              "y": {
                                "grid": {
                                  "drawBorder": false,
                                  "color": "#eeeef1"
                                },
                                "min": 25,
                                "max": 150,
                                "ticks": {
                                  "stepSize": 25,
                                  "color": "rgba(0, 0, 0, 0.4)",
                                  "padding": 10
                                }
                              },
                              "x": {
                                "grid": {
                                  "display": false,
                                  "drawBorder": false
                                },
                                "ticks": {
                                  "labelOffset": 20,
                                  "maxTicksLimit": 11,
                                  "padding": 20,
                                  "maxRotation": 0,
                                  "minRotation": 0,
                                  "font": {
                                    "size": 12
                                  },
                                  "color": "rgba(0, 0, 0, 0.4)"
                                }
                              }
                            },
                            "hover": {
                               "mode": "nearest",
                               "intersect": false
                             },
                            "plugins": {
                              "tooltip": {
                                "prefix": "$",
                                "intersect": false
                              }
                            }
                          }
                        }'>
              </canvas>
            </div>
            <!-- End Chartjs -->
              
            

Bar chart

  • Preview
  • HTML
35%
              
                <div class="d-flex align-items-center mb-4">
              <span class="h1 mb-0">35%</span>
            </div>

            <!-- Bar Chart -->
            <div class="chartjs-custom">
              <canvas id="ecommerce-sales" class="js-chart" style="height: 20rem;"
                      data-hs-chartjs-options='{
                              "type": "bar",
                              "data": {
                                "labels": ["May 1", "May 2", "May 3", "May 4", "May 5", "May 6", "May 7", "May 8", "May 9", "May 10"],
                                "datasets": [{
                                  "data": [200, 300, 290, 350, 150, 350, 300, 100, 125, 220],
                                  "backgroundColor": "#377dff",
                                  "hoverBackgroundColor": "#377dff",
                                  "borderColor": "#377dff",
                                  "maxBarThickness": "10"
                                }]
                              },
                              "options": {
                                "scales": {
                                  "y": {
                                    "grid": {
                                      "color": "#e7eaf3",
                                      "drawBorder": false,
                                      "zeroLineColor": "#e7eaf3"
                                    },
                                    "ticks": {
                                      "beginAtZero": true,
                                      "stepSize": 100,
                                      "fontSize": 12,
                                      "fontColor": "#97a4af",
                                      "fontFamily": "Open Sans, sans-serif",
                                      "padding": 10,
                                      "postfix": "$"
                                    }
                                  },
                                  "x": {
                                    "grid": {
                                      "display": false,
                                      "drawBorder": false
                                    },
                                    "ticks": {
                                      "font": {
                                        "size": 12,
                                        "family": "Open Sans, sans-serif"
                                      },
                                      "color": "#97a4af",
                                      "padding": 5
                                    },
                                    "categoryPercentage": 0.5
                                  }
                                },
                                "cornerRadius": 2,
                                "plugins": {
                                  "tooltip": {
                                  "prefix": "$",
                                  "hasIndicator": true,
                                  "mode": "index",
                                  "intersect": false
                                  }
                                },
                                "hover": {
                                  "mode": "nearest",
                                  "intersect": true
                                }
                              }
                            }'></canvas>
            </div>
            <!-- End Bar Chart -->
              
            

Updating bar chart

  • Preview
  • HTML
  • JS
  • This week
  • Last week
              
                <div class="d-flex justify-content-end mb-5">
              <!-- Nav -->
              <ul class="nav nav-segment" id="expensesTabEg1" role="tablist">
                <li class="nav-item" data-toggle="chart-bar" data-datasets="thisWeek" data-trigger="click" data-action="toggle">
                  <a class="nav-link active" href="javascript:;" data-bs-toggle="tab">This week</a>
                </li>
                <li class="nav-item" data-toggle="chart-bar" data-datasets="lastWeek" data-trigger="click" data-action="toggle">
                  <a class="nav-link" href="javascript:;" data-bs-toggle="tab">Last week</a>
                </li>
              </ul>
              <!-- End Nav -->
            </div>

            <!-- Bar Chart -->
            <div class="chartjs-custom">
              <canvas id="updatingBarChart" style="height: 20rem;"
                      data-hs-chartjs-options='{
                              "type": "bar",
                              "data": {
                                "labels": ["May 1", "May 2", "May 3", "May 4", "May 5", "May 6", "May 7", "May 8", "May 9", "May 10"],
                                "datasets": [{
                                  "data": [200, 300, 290, 350, 150, 350, 300, 100, 125, 220],
                                  "backgroundColor": "#377dff",
                                  "hoverBackgroundColor": "#377dff",
                                  "borderColor": "#377dff",
                                  "maxBarThickness": "10"
                                },
                                {
                                  "data": [150, 230, 382, 204, 169, 290, 300, 100, 300, 225, 120],
                                  "backgroundColor": "#e7eaf3",
                                  "borderColor": "#e7eaf3",
                                  "maxBarThickness": "10"
                                }]
                              },
                              "options": {
                                "scales": {
                                  "y": {
                                    "grid": {
                                      "color": "#e7eaf3",
                                      "drawBorder": false,
                                      "zeroLineColor": "#e7eaf3"
                                    },
                                    "ticks": {
                                      "beginAtZero": true,
                                      "stepSize": 100,
                                      "fontSize": 12,
                                      "fontColor": "#97a4af",
                                      "fontFamily": "Open Sans, sans-serif",
                                      "padding": 10,
                                      "postfix": "$"
                                    }
                                  },
                                  "x": {
                                    "grid": {
                                      "display": false,
                                      "drawBorder": false
                                    },
                                    "ticks": {
                                      "font": {
                                        "size": 12,
                                        "family": "Open Sans, sans-serif"
                                      },
                                      "color": "#97a4af",
                                      "padding": 5
                                    },
                                    "categoryPercentage": 0.5
                                  }
                                },
                                "cornerRadius": 2,
                                "plugins": {
                                  "tooltip": {
                                    "prefix": "$",
                                    "hasIndicator": true,
                                    "mode": "index",
                                    "intersect": false
                                  }
                                },
                                "hover": {
                                  "mode": "nearest",
                                  "intersect": true
                                }
                              }
                            }'></canvas>
            </div>
            <!-- End Bar Chart -->
              
            
              
                <script>
                  (function () {
                    HSCore.components.HSChartJS.init(document.querySelector('#updatingBarChart'));

                    const updatingBarChart = HSCore.components.HSChartJS.getItem('updatingBarChart')

                    // Call when tab is clicked
                    document.querySelectorAll('[data-toggle="chart-bar"]').forEach(item => {
                      item.addEventListener('click', e => {
                        let keyDataset = e.currentTarget.getAttribute('data-datasets')

                        if (keyDataset === 'lastWeek') {
                          updatingBarChart.data.labels = ["Apr 22", "Apr 23", "Apr 24", "Apr 25", "Apr 26", "Apr 27", "Apr 28", "Apr 29", "Apr 30", "Apr 31"];
                          updatingBarChart.data.datasets = [
                            {
                              "data": [120, 250, 300, 200, 300, 290, 350, 100, 125, 320],
                              "backgroundColor": "#377dff",
                              "hoverBackgroundColor": "#377dff",
                              "borderColor": "#377dff",
                              "maxBarThickness": 10
                            },
                            {
                              "data": [250, 130, 322, 144, 129, 300, 260, 120, 260, 245, 110],
                              "backgroundColor": "#e7eaf3",
                              "borderColor": "#e7eaf3",
                              "maxBarThickness": 10
                            }
                          ];
                          updatingBarChart.update();
                        } else {
                          updatingBarChart.data.labels = ["May 1", "May 2", "May 3", "May 4", "May 5", "May 6", "May 7", "May 8", "May 9", "May 10"];
                          updatingBarChart.data.datasets = [
                            {
                              "data": [200, 300, 290, 350, 150, 350, 300, 100, 125, 220],
                              "backgroundColor": "#377dff",
                              "hoverBackgroundColor": "#377dff",
                              "borderColor": "#377dff",
                              "maxBarThickness": 10
                            },
                            {
                              "data": [150, 230, 382, 204, 169, 290, 300, 100, 300, 225, 120],
                              "backgroundColor": "#e7eaf3",
                              "borderColor": "#e7eaf3",
                              "maxBarThickness": 10
                            }
                          ]
                          updatingBarChart.update();
                        }
                      })
                    })
                  })()
                </script>
              
            

Doughnut chart

  • Preview
  • HTML
$2,332.00 Marketing
$10,452.00 Bills
$56,856.00 Others
              
                <!-- Pie Chart -->
            <div class="chartjs-custom mb-3 mb-sm-5" style="height: 14rem;">
              <canvas id="doughnut-chart" class="js-chart"
                      data-hs-chartjs-options='{
                              "type": "doughnut",
                              "data": {
                                "labels": ["USD", "USD", "USD"],
                                "datasets": [{
                                  "data": [45, 25, 30],
                                  "backgroundColor": ["#377dff", "#00c9db", "#e7eaf3"],
                                  "borderWidth": 5,
                                  "hoverBorderColor": "#fff"
                                }]
                              },
                              "options": {
                                "cutout": "80%",
                                "plugins": {
                                  "tooltip": {
                                    "postfix": "k",
                                    "hasIndicator": true,
                                    "mode": "index",
                                    "intersect": false
                                  }
                                },
                                "hover": {
                                  "mode": "nearest",
                                  "intersect": true
                                }
                              }
                            }'></canvas>
            </div>
            <!-- End Pie Chart -->

            <!-- Legend Indicators -->
            <div class="row justify-content-center">
              <div class="col-auto mb-3 mb-sm-0">
                <span class="card-title h4">$2,332.00</span>
                <span class="legend-indicator bg-primary"></span> Marketing
              </div>

              <div class="col-auto mb-3 mb-sm-0">
                <span class="card-title h4">$10,452.00</span>
                <span class="legend-indicator bg-info"></span> Bills
              </div>

              <div class="col-auto">
                <span class="card-title h4">$56,856.00</span>
                <span class="legend-indicator"></span> Others
              </div>
            </div>
            <!-- End Legend Indicators -->
              
            

Updating doughnut chart

  • Preview
  • HTML
  • JS
  • This week
  • Last week
$2,332.00 Marketing
$10,452.00 Bills
$56,856.00 Others
              
                <div class="d-flex justify-content-end mb-3">
              <!-- Nav -->
              <ul class="nav nav-segment" id="expensesTabEg2" role="tablist">
                <li class="nav-item" data-toggle="chart-doughnut" data-datasets="0" data-trigger="click" data-action="toggle">
                  <a class="nav-link active" href="javascript:;" data-bs-toggle="tab">This week</a>
                </li>
                <li class="nav-item" data-toggle="chart-doughnut" data-datasets="1" data-trigger="click" data-action="toggle">
                  <a class="nav-link" href="javascript:;" data-bs-toggle="tab">Last week</a>
                </li>
              </ul>
              <!-- End Nav -->
            </div>

            <!-- Pie Chart -->
            <div class="chartjs-custom mb-3 mb-sm-5" style="height: 14rem;">
              <canvas id="updatingDoughnutChart"
                      data-hs-chartjs-options='{
                              "type": "doughnut",
                              "data": {
                                "labels": ["USD", "USD", "USD"],
                                "datasets": [{
                                  "backgroundColor": ["#377dff", "#00c9db", "#e7eaf3"],
                                  "borderWidth": 5,
                                  "hoverBorderColor": "#fff"
                                }]
                              },
                              "options": {
                                "cutout": "80%",
                                "plugins": {
                                  "tooltip": {
                                    "postfix": "k",
                                    "hasIndicator": true,
                                    "mode": "index",
                                    "intersect": false
                                  }
                                },
                                "hover": {
                                  "mode": "nearest",
                                  "intersect": true
                                }
                              }
                            }'></canvas>
            </div>
            <!-- End Pie Chart -->

            <!-- Legend Indicators -->
            <div class="row justify-content-center">
              <div class="col-auto mb-3 mb-sm-0">
                <span class="card-title h4">$2,332.00</span>
                <span class="legend-indicator bg-primary"></span> Marketing
              </div>

              <div class="col-auto mb-3 mb-sm-0">
                <span class="card-title h4">$10,452.00</span>
                <span class="legend-indicator bg-info"></span> Bills
              </div>

              <div class="col-auto">
                <span class="card-title h4">$56,856.00</span>
                <span class="legend-indicator"></span> Others
              </div>
            </div>
            <!-- End Legend Indicators -->
              
            
              
                <script>
                  (function () {
                    HSCore.components.HSChartJS.init(document.querySelector('#updatingDoughnutChart'));

                    // Datasets for chart, can be loaded from AJAX request
                    var updatingDoughnutChartDatasets = [
                      [
                        [45, 25, 30]
                      ],
                      [
                        [35, 50, 15]
                      ]
                    ]

                    const updatingDoughnutChart = HSCore.components.HSChartJS.getItem('updatingDoughnutChart')

                    // Set datasets for chart when page is loaded
                    updatingDoughnutChart.data.datasets.forEach(function(dataset, key) {
                      dataset.data = updatingDoughnutChartDatasets[0][key];
                    });
                    updatingDoughnutChart.update();

                    // Call when tab is clicked
                    document.querySelectorAll('[data-toggle="chart-doughnut"]').forEach(item => {
                      item.addEventListener('click', e => {
                        let keyDataset = e.currentTarget.getAttribute('data-datasets')

                        // Update datasets for chart
                        updatingDoughnutChart.data.datasets.forEach(function(dataset, key) {
                          dataset.data = updatingDoughnutChartDatasets[keyDataset][key];
                        });
                        updatingDoughnutChart.update();
                      })
                    })
                  })()
                </script>
              
            

Half circle chart

  • Preview
  • HTML
  • JS
Project balance $150,238.00
              
                 <!-- Chart Half -->
            <div class="chartjs-doughnut-custom" style="height: 12rem;">
              <canvas id="doughnutHalfChart" class="js-chartjs-doughnut-half"
                      data-hs-chartjs-options='{
                            "type": "doughnut",
                            "data": {
                              "labels": ["Current status", "Goal"],
                              "datasets": [{
                                "data": [64, 35],
                                "backgroundColor": ["#377dff", "rgba(55, 125, 255, 0.35)"],
                                "borderWidth": 4,
                                "hoverBorderColor": "#ffffff"
                              }]
                            }
                          }'></canvas>

              <div class="chartjs-doughnut-custom-stat">
                <small class="text-cap">Project balance</small>
                <span class="h1">$150,238.00</span>
              </div>
            </div>
            <!-- End Chart Half -->
              
            
              
                <script>
                  (function () {
                    HSCore.components.HSChartJS.init(document.querySelector('.js-chartjs-doughnut-half'), {
                      options: {
                        plugins: {
                          tooltip: {
                            postfix: "%"
                          }
                        },
                        cutout: '85%',
                        rotation: '270',
                        circumference: '180'
                      }
                    })
                  })
                </script>
              
            

Updating half circle chart

  • Preview
  • HTML
  • JS
Project balance $150,238.00
              
                <div class="d-flex justify-content-end mb-5">
              <!-- Checkbox Switch -->
              <div class="form-check form-switch form-switch-between">
                <input id="updatingBarChartControl" class="form-check-input" type="checkbox">
              </div>
              <!-- End Checkbox Switch -->
            </div>

            <!-- Chart Half -->
            <div class="chartjs-doughnut-custom" style="height: 12rem;">
              <canvas id="updatingDoughnutHalfChart" class="js-chartjs-doughnut-half-dynamic"
                      data-hs-chartjs-options='{
                            "type": "doughnut",
                            "data": {
                              "labels": ["Current status", "Goal"],
                              "datasets": [{
                                "data": [64, 35],
                                "backgroundColor": ["#377dff", "rgba(55, 125, 255, 0.35)"],
                                "borderWidth": 4,
                                "hoverBorderColor": "#ffffff"
                              }]
                            }
                          }'></canvas>

              <div class="chartjs-doughnut-custom-stat">
                <small class="text-cap">Project balance</small>
                <span id="js-chartjs-half-balance" class="h1">$150,238.00</span>
              </div>
            </div>
            <!-- End Chart Half -->
              
            
              
                <script>
                  (function () {
                    HSCore.components.HSChartJS.init(document.querySelector('.js-chartjs-doughnut-half-dynamic'), {
                      options: {
                        tooltips: {
                          postfix: "%"
                        },
                        cutout: '85%',
                        rotation: '270',
                        circumference: '180'
                      }
                    })

                    const halfChart = HSCore.components.HSChartJS.getItem('updatingDoughnutHalfChart')

                    document.querySelector('#updatingBarChartControl').addEventListener("change", e => {
                      let $balance = document.querySelector('#js-chartjs-half-balance')
                      if (e.target.checked) {
                        halfChart.data.datasets[0].data[1] = 90
                        $balance.innerHTML = "$110,351.00"
                      } else {
                        halfChart.data.datasets[0].data[1] = 35
                        $balance.innerHTML = "$150,238.00"
                      }

                      halfChart.update()
                    })
                  })()
                </script>
              
            

Bubble chart

  • Preview
  • HTML
  • JS
This example uses Datalabels plugin for Chart.js library.
New
Pending
Failed
              
                <!-- Chart -->
            <div class="chartjs-custom mx-auto" style="height: 20rem;">
              <canvas class="js-chart-datalabels"
                      data-hs-chartjs-options='{
                              "type": "bubble",
                              "data": {
                                "datasets": [
                                  {
                                    "label": "Label 1",
                                    "data": [
                                      {"x": 50, "y": 65, "r": 99}
                                    ],
                                    "color": "#fff",
                                    "backgroundColor": "rgba(55, 125, 255, 0.9)",
                                    "borderColor": "transparent"
                                  },
                                  {
                                    "label": "Label 2",
                                    "data": [
                                      {"x": 46, "y": 42, "r": 65}
                                    ],
                                    "color": "#fff",
                                    "backgroundColor": "rgba(100, 0, 214, 0.8)",
                                    "borderColor": "transparent"
                                  },
                                  {
                                    "label": "Label 3",
                                    "data": [
                                      {"x": 48, "y": 15, "r": 38}
                                    ],
                                    "color": "#fff",
                                    "backgroundColor": "#00c9db",
                                    "borderColor": "transparent"
                                  },
                                  {
                                    "label": "Label 3",
                                    "data": [
                                      {"x": 55, "y": 2, "r": 61}
                                    ],
                                    "color": "#fff",
                                    "backgroundColor": "#4338ca",
                                    "borderColor": "transparent"
                                  }
                                ]
                              },
                              "options": {
                                "scales": {
                                  "y": {
                                    "grid": {
                                      "display": false,
                                      "drawBorder": false
                                    },
                                    "ticks": {
                                      "display": false,
                                      "beginAtZero": true
                                    },
                                    "max": 500
                                  },
                                  "x": {
                                   "grid": {
                                      "display": false,
                                      "drawBorder": false
                                    },
                                    "ticks": {
                                      "display": false,
                                      "max": 100,
                                      "beginAtZero": true
                                    }
                                  }
                                },
                                "plugins": {
                                  "tooltip": false
                                }
                              }
                            }'></canvas>
            </div>
            <!-- End Chart -->

            <!-- Legend Indicators -->
            <div class="row justify-content-center">
              <div class="col-auto">
                <span class="legend-indicator bg-primary"></span> New
              </div>

              <div class="col-auto">
                <span class="legend-indicator" style="background-color: #7000f2;"></span> Pending
              </div>

              <div class="col-auto">
                <span class="legend-indicator bg-info"></span> Failed
              </div>
            </div>
            <!-- End Legend Indicators -->
              
            
              
                <!-- JS Implementing Plugins -->
                <script src="../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js"></script>

                <script>
                  (function () {
                   document.querySelectorAll('.js-chart-datalabels').forEach(item => {
                      HSCore.components.HSChartJS.init(item, {
                        plugins: [ChartDataLabels],
                        options: {
                          plugins: {
                            datalabels: {
                              color: function(context) {
                                var value = context.dataset.data[context.dataIndex];
                                return value.r < 20 ? context.dataset.backgroundColor : context.dataset.color;
                              },
                              font: function(context) {
                                var value = context.dataset.data[context.dataIndex],
                                        fontSize = 25;

                                if (value.r > 50) {
                                  fontSize = 35;
                                }

                                if (value.r > 70) {
                                  fontSize = 55;
                                }

                                return {
                                  weight: 'lighter',
                                  size: fontSize
                                };
                              },
                              formatter: function (value) {
                                return value.r
                              },
                              offset: 2,
                              padding: 0
                            }
                          }
                        },
                      })
                    })
                  })()
                </script>
              
            

Matrix chart

  • Preview
  • HTML
  • JS
This example uses Chart matrix module for Chart.js library.
                  
                    <!-- Matrix Chart -->
                    <div class="chartjs-matrix-custom mb-3" style="min-width: 100%; width: 700px;">
                      <canvas class="js-chart-matrix"
                              style='min-height: 150px;'
                              data-hs-chartjs-options='{
                                  "options": {
                                    "matrixBackgroundColord": {
                                       "color": "#377dff",
                                       "accent": 50,
                                       "additionToValue": 2
                                    },
                                    "matrixLegend": {
                                      "container": "#matrixLegend"
                                    }
                                  }
                                }'></canvas>
                    </div>
                    <!-- End Matrix Chart -->
    
                    <!-- Matrix Legend -->
                    <ul id="matrixLegend" class="mb-0"></ul>
                  
                
                  
                    <!-- JS Implementing Plugins -->
                    <script src="../node_modules/chart.js/dist/Chart.min.js"></script>
                    <script src="../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js"></script>
                    <script src="../node_modules/daterangepicker/moment.min.js"></script>
                    <script src="../node_modules/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
    
                    <!-- JS Front -->
                    <script src="../assets/js/hs.chartjs.js"></script>
                    <script src="../assets/js/hs.chartjs-matrix.js"></script>
    
                    <script>
                      (function () {
                        // INITIALIZATION OF MATRIX CHARTJS WITH CHARTJS MATRIX PLUGIN
                        // =======================================================
                        function generateHoursData() {
                          var data = [];
                          var dt = moment().subtract(365, 'days').startOf('day');
                          var end = moment().startOf('day');
                          while(dt <= end) {
                            data.push({
                              x: dt.format('YYYY-MM-DD'),
                              y: dt.format('e'),
                              d: dt.format('YYYY-MM-DD'),
                              v: Math.random() * 24
                            });
                            dt = dt.add(1, 'day');
                          }
                          return data;
                        }
    
                        HSCore.components.HSChartMatrixJS.init(document.querySelector('.js-chart-matrix'), {
                          data: {
                            datasets: [{
                              label: 'Commits',
                              data: generateHoursData(),
                              width(c) {
                                const a = c.chart.chartArea || {};
                                return (a.right - a.left) / 70;
                              },
                              height(c) {
                                const a = c.chart.chartArea || {};
                                return (a.bottom - a.top) / 7;
                              }
                            }]
                          },
                          options: {
                            aspectRatio: 5,
                            plugins: {
                              tooltip: {
                                callbacks: {
                                  title: function() { return '';},
                                  label: function(item) {
                                    var v = item.dataset.data[item.datasetIndex]
    
                                    if (v.v.toFixed() > 0) {
                                      return '<span class="fw-semibold">' + v.v.toFixed() + 'hours</span> on ' + v.d;
                                    }  else {
                                      return '<span class="fw-semibold">No time</span> on ' + v.d;
                                    }
                                  }
                                }
                              },
                            },
                            scales: {
                              y: {
                                type: 'time',
                                offset: true,
                                time: {
                                  unit: 'day',
                                  round: 'day',
                                  isoWeekday: 1,
                                  parser: 'i',
                                  displayFormats: {
                                    day: 'iiiiii'
                                  }
                                },
                                reverse: true,
                                ticks: {
                                  font: {
                                    size: 12,
                                  },
                                  maxTicksLimit: 5,
                                  color: "rgba(22, 52, 90, 0.5)",
                                  maxRotation: 0,
                                  autoSkip: true
                                },
                                grid: {
                                  display: false,
                                  drawBorder: false,
                                  tickLength: 0
                                }
                              },
                              x: {
                                type: 'time',
                                position: 'bottom',
                                offset: true,
                                time: {
                                  unit: 'week',
                                  round: 'week',
                                  isoWeekday: 1,
                                  displayFormats: {
                                    week: 'MMM dd'
                                  }
                                },
                                ticks: {
                                  font: {
                                    size: 12,
                                  },
                                  maxTicksLimit: 5,
                                  color: "rgba(22, 52, 90, 0.5)",
                                  maxRotation: 0,
                                  autoSkip: true
                                },
                                grid: {
                                  display: false,
                                  drawBorder: false,
                                  tickLength: 0,
                                }
                              }
                            }
                          }
                        })
                      })()
                    </script>
                  
                

    ChartJS methods

    Parameters Description Default value
    options.scales.y.ticks.prefix Preffix for y. false
    options.scales.y.ticks.postfix Postfix for y. false
    options.scales.y.ticks.metric Metric output for axes (1k, 1kk, etc..). false
    options.responsive Responsive chart. true
    options.maintainAspectRatio Maintain the original canvas aspect ratio (width / height) when resizing. false
    options.legend.display Legend for chart. false
    options.plugins.tooltip.enabled Enable or disable tooltips. false
    options.plugins.tooltip.prefix Prefix for tooltip text. false
    options.plugins.tooltip.postfix Postfix for tooltip text. false
    options.plugins.tooltip.yearStamp Added year after title. true
    options.plugins.tooltip.hasIndicator Add indicator for tooltip. false
    options.plugins.tooltip.indicatorWidth Width indicator. 8px
    options.plugins.tooltip.indicatorHeight Height indicator. 8px
    options.plugins.tooltip.lineMode Set line tooltip type. false
    options.plugins.tooltip.lineWithLineColor Set color for line. null
    options.plugins.tooltip.lineWithLineBottomOffset Offset of the top for line. 7
    options.plugins.tooltip.lineWithLineBottomOffset Offset of the bottom for line. 43
    options.gradientPosition Gradient position. { x0: 0, y0: 0, x1: 0, y1: 0 }

    Matrix methods

    Parameters Description Default value
    options.matrixBackgroundColor.color Set color for matrix chart. null
    options.matrixBackgroundColor.accent Set accent color for matrix chart. Usually this is the maximum value from datasets. null
    options.matrixBackgroundColor.nullColor Set custom color for empty items in matrix chart. false
    options.matrixBackgroundColor.additionToValue Add addition value to value of item in matrix chart. 5
    options.matrixLegend.container Wrapper for custom legends. 5
    options.matrixLegend.stepSize Step size for legends. max / 10
    options.matrixLegend.metric Metric output for legend values (1k, 1kk, etc..). false