0.3.0 • Published 3 years ago

chartjs-gauge v0.3.0

Weekly downloads
1,446
License
-
Repository
github
Last release
3 years ago

chartjs-gauge logo chartjs-gauge

Simple gauge chart for Chart.js

Samples

Install

  • yarn install: yarn add chart.js chartjs-gauge
  • npm install: npm install --save chart.js chartjs-gauge

Configuration Options

The gauge chart is based on the Doughnut type. It defines the following additional configuration options. These options are merged with the global chart configuration options, Chart.defaults.global, to form the options passed to the chart.

NameTypeDefaultDescription
needle.radiusPercentagenumber2Needle circle radius as the percentage of the chart area width.
needle.widthPercentagenumber3.2Needle width as the percentage of the chart area width.
needle.lengthPercentagenumber80Needle length as the percentage of the interval between inner radius (0%) and outer radius (100%) of the arc.
needle.colorColor'rgba(0, 0, 0, 1)'The color of the needle.
valueLabel.displaybooleantrueIf true, display the value label.
valueLabel.formatterfunctionMath.roundReturns the string representation of the value as it should be displayed on the chart.
valueLabel.fontSizenumberundefinedThe font size of the label.
valueLabel.colorColor'rgba(255, 255, 255, 1)'The text color of the label.
valueLabel.backgroundColorColor'rgba(0, 0, 0, 1)'The background color of the label.
valueLabel.borderRadiusnumber5Border radius of the label.
valueLabel.padding.topnumber5Top padding of the label.
valueLabel.padding.rightnumber5Right padding of the label.
valueLabel.padding.bottomnumber5Bottom padding of the label.
valueLabel.padding.leftnumber5Left padding of the label.
valueLabel.bottomMarginPercentagenumber5Bottom margin as the percentage of the chart area width.

Default Options

It is common to want to apply a configuration setting to all created gauge charts. The global gauge chart settings are stored in Chart.defaults.gauge. Changing the global options only affects charts created after the change. Existing charts are not changed.

For example, to configure all line charts with radiusPercentage = 5 you would do:

Chart.defaults.gauge.needle.radiusPercentage = 5;

Dataset Properties

The gauge chart requires a value to be specified for the dataset. This is used to draw the needle for the dataset.

NameTypeDefaultDescription
valuenumberundefinedValue used for the needle.
minValuenumber0Used to offset the start value.

Example

var ctx = document.getElementById("canvas").getContext("2d");

var chart = new Chart(ctx, {
  type: 'gauge',
  data: {
    datasets: [{
      value: 0.5,
      minValue: 0,
      data: [1, 2, 3, 4],
      backgroundColor: ['green', 'yellow', 'orange', 'red'],
    }]
  },
  options: {
    needle: {
      radiusPercentage: 2,
      widthPercentage: 3.2,
      lengthPercentage: 80,
      color: 'rgba(0, 0, 0, 1)'
    },
    valueLabel: {
      display: true,
      formatter: (value) => {
        return '$' + Math.round(value);
      },
      color: 'rgba(255, 255, 255, 1)',
      backgroundColor: 'rgba(0, 0, 0, 1)',
      borderRadius: 5,
      padding: {
        top: 10,
        bottom: 10
      }
    }
  }
});

License

chartjs-gauge is available under the MIT license.

0.3.0

3 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago