Option reference

Chart legend

The legend tells the reader which colour is which dataset. Move it, hide it, or change how its entries look.

The legend is the legend plugin, options.plugins.legend. Each entry's text is the dataset's label; on a pie, doughnut or polar area chart there is one entry per slice, and its text comes from data.labels. The theme shows the legend at the top left when a dataset has a label or there is more than one dataset, and on the right for pie, doughnut and polar area charts. Anything you set wins.

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

Legend at the bottom

position takes top, bottom, left or right. The theme puts the legend at the top left.

Bar chart with two datasets, web and app, and the legend below the chart
Open in the editor

The part of the config that matters

{
  "options": {
    "plugins": {
      "legend": {
        "position": "bottom"
      }
    }
  }
}

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%22plugins%22%3A%7B%22legend%22%3A%7B%22position%22%3A%22bottom%22%7D%7D%7D%7D

Legend on the right

On the left or the right the entries stack in a column and the plot gets narrower.

Bar chart with two datasets, web and app, and the legend in a column on the right
Open in the editor

The part of the config that matters

{
  "options": {
    "plugins": {
      "legend": {
        "position": "right"
      }
    }
  }
}

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%22plugins%22%3A%7B%22legend%22%3A%7B%22position%22%3A%22right%22%7D%7D%7D%7D

No legend

display false removes it. Do this when the title already says what the line is.

Line chart of signups per week with a title and no legend
Open in the editor

The part of the config that matters

{
  "options": {
    "plugins": {
      "legend": {
        "display": false
      }
    }
  }
}

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%22Signups%22%2C%22data%22%3A%5B24%2C37%2C31%2C45%2C39%2C52%5D%7D%5D%7D%2C%22options%22%3A%7B%22plugins%22%3A%7B%22title%22%3A%7B%22display%22%3Atrue%2C%22text%22%3A%22Signups%20per%20week%22%7D%2C%22legend%22%3A%7B%22display%22%3Afalse%7D%7D%7D%7D

Markers, text and alignment

The theme draws round markers. pointStyle changes their shape, boxWidth and boxHeight their size, font the text, and align moves the row to start, center or end.

Bar chart with two datasets and a legend of larger square markers and larger text, aligned to the right
Open in the editor

The part of the config that matters

{
  "options": {
    "plugins": {
      "legend": {
        "align": "end",
        "labels": {
          "pointStyle": "rect",
          "boxWidth": 12,
          "boxHeight": 12,
          "font": {
            "size": 14
          }
        }
      }
    }
  }
}

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%22plugins%22%3A%7B%22legend%22%3A%7B%22align%22%3A%22end%22%2C%22labels%22%3A%7B%22pointStyle%22%3A%22rect%22%2C%22boxWidth%22%3A12%2C%22boxHeight%22%3A12%2C%22font%22%3A%7B%22size%22%3A14%7D%7D%7D%7D%7D%7D

Things to know

More options