Option reference

Chart axes

Axes set what range the numbers are read against. Fix their ends, stack the bars, turn the chart on its side, or hide an axis.

Axes are options.scales, with one entry per axis. A bar, line, scatter or bubble chart has x and y; a radar and a polar area chart have r. On a bar chart, x holds the labels and y the numbers. In a line chart the value axis starts near the lowest number unless you set beginAtZero: true; in a bar chart it starts at zero. The theme draws only the horizontal grid lines and aims for about six ticks.

The numbers in the images are sample data. Each image is what the URL under it returns.

Minimum, maximum and a title

min and max fix the ends of an axis. title.text names it, which is where a unit goes.

Line chart of the share of tasks done per week, on a value axis fixed from 0 to 100 and titled Done (%)
Open in the editor

The part of the config that matters

{
  "options": {
    "scales": {
      "y": {
        "min": 0,
        "max": 100,
        "title": {
          "display": true,
          "text": "Done (%)"
        }
      }
    }
  }
}

The full URL

https://chartpng.dev/chart?w=480&h=280&dpr=2&c=%7B%22type%22%3A%22line%22%2C%22data%22%3A%7B%22labels%22%3A%5B%22W1%22%2C%22W2%22%2C%22W3%22%2C%22W4%22%2C%22W5%22%2C%22W6%22%5D%2C%22datasets%22%3A%5B%7B%22label%22%3A%22Tasks%20done%22%2C%22data%22%3A%5B62%2C68%2C71%2C66%2C79%2C84%5D%7D%5D%7D%2C%22options%22%3A%7B%22scales%22%3A%7B%22y%22%3A%7B%22min%22%3A0%2C%22max%22%3A100%2C%22title%22%3A%7B%22display%22%3Atrue%2C%22text%22%3A%22Done%20(%25)%22%7D%7D%7D%7D%7D

Stacked

stacked on both axes puts the datasets on top of each other. The number above a bar is still the value of its own dataset.

Stacked bar chart of web and app signups per week
Open in the editor

The part of the config that matters

{
  "options": {
    "scales": {
      "x": {
        "stacked": true
      },
      "y": {
        "stacked": true
      }
    }
  }
}

The full URL

https://chartpng.dev/chart?w=480&h=280&dpr=2&c=%7B%22type%22%3A%22bar%22%2C%22data%22%3A%7B%22labels%22%3A%5B%22W1%22%2C%22W2%22%2C%22W3%22%2C%22W4%22%2C%22W5%22%2C%22W6%22%5D%2C%22datasets%22%3A%5B%7B%22label%22%3A%22Web%22%2C%22data%22%3A%5B24%2C37%2C31%2C45%2C39%2C52%5D%7D%2C%7B%22label%22%3A%22App%22%2C%22data%22%3A%5B12%2C18%2C22%2C21%2C30%2C34%5D%7D%5D%7D%2C%22options%22%3A%7B%22scales%22%3A%7B%22x%22%3A%7B%22stacked%22%3Atrue%7D%2C%22y%22%3A%7B%22stacked%22%3Atrue%7D%7D%7D%7D

A horizontal chart

indexAxis y turns the bars sideways. The categories are now on y and the numbers on x, so the value axis options go under x.

Horizontal bar chart of signups per week, with the value axis fixed from 0 to 60
Open in the editor

The part of the config that matters

{
  "options": {
    "indexAxis": "y",
    "scales": {
      "x": {
        "min": 0,
        "max": 60
      }
    }
  }
}

The full URL

https://chartpng.dev/chart?w=480&h=280&dpr=2&c=%7B%22type%22%3A%22bar%22%2C%22data%22%3A%7B%22labels%22%3A%5B%22W1%22%2C%22W2%22%2C%22W3%22%2C%22W4%22%2C%22W5%22%2C%22W6%22%5D%2C%22datasets%22%3A%5B%7B%22label%22%3A%22Signups%22%2C%22data%22%3A%5B24%2C37%2C31%2C45%2C39%2C52%5D%7D%5D%7D%2C%22options%22%3A%7B%22indexAxis%22%3A%22y%22%2C%22scales%22%3A%7B%22x%22%3A%7B%22min%22%3A0%2C%22max%22%3A60%7D%7D%7D%7D

Hiding an axis and its grid

display false on an axis removes its line, its ticks and its labels. grid.display false removes only the lines across the plot. The theme still prints each value on its bar.

Bar chart of signups per week with no value axis and no vertical grid lines, the numbers printed above the bars
Open in the editor

The part of the config that matters

{
  "options": {
    "scales": {
      "y": {
        "display": false
      },
      "x": {
        "grid": {
          "display": false
        }
      }
    }
  }
}

The full URL

https://chartpng.dev/chart?w=480&h=280&dpr=2&c=%7B%22type%22%3A%22bar%22%2C%22data%22%3A%7B%22labels%22%3A%5B%22W1%22%2C%22W2%22%2C%22W3%22%2C%22W4%22%2C%22W5%22%2C%22W6%22%5D%2C%22datasets%22%3A%5B%7B%22label%22%3A%22Signups%22%2C%22data%22%3A%5B24%2C37%2C31%2C45%2C39%2C52%5D%7D%5D%7D%2C%22options%22%3A%7B%22scales%22%3A%7B%22y%22%3A%7B%22display%22%3Afalse%7D%2C%22x%22%3A%7B%22grid%22%3A%7B%22display%22%3Afalse%7D%7D%7D%7D%7D

More axis options

Units on the ticks

A prefix or a suffix on every tick, such as $ or %, is a tick callback in Chart.js, and a callback is code, which ChartPNG removes from a config. Put the unit in the axis title, as in the first example, or in the labels. The ranking, funnel, gauge and KPI presets take prefix and suffixfor the numbers they print: see report presets and the ranking chart.

Text on chosen ticks

A linear or logarithmic axis takes ticks.labels, a map from a value to the text drawn at it, as data instead of a callback:{ "scales": { "x": { "min": 0, "max": 2, "ticks": { "labels": { "0": "0", "1.7": "+50 %" } } } } }. The axis then shows ticks at exactly those values, with that text, and no other. A value outside the axis is not drawn, so set min and max to bring it in. At most 50 entries, and the keys are numbers; anything else, or a category axis, is a 400 with the code tick_labels.

Text on the chart

A label by each point comes from the datalabels plugin: set options.plugins.datalabels.display to true (or "auto" to hide labels that overlap) and give each point alabel, as in { "x": 4, "y": 120, "r": 8, "label": "Zontes +128 %" }. Nothing is drawn until you turn it on. Lines, boxes and captions on the plot come from options.plugins.annotation.annotations, at most 50, with text as a string or a list of strings in content. An image, a handler such as click or enter, or any other kind of content is a 400. Both are in the@chartpng/render README with a worked example.

What does not work

More options