Use ChartJS with DataView

There is a Chart JS Obsidian Plugin, but I wanted to use the latest and greatest version of Chart JS.

This is similar to a recent post about using mermaid js with dataview.

Here’s how you can do it in a dataviewjs code block:

const ctx = dv.el("canvas", null);

await import("");

new Chart(ctx, {
    type: 'bar',
    data: {
      labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
      datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
    options: {
      scales: {
        y: {
          beginAtZero: true

How you can fit the page dimention when you want export to a pdf file?

Thanks a lot!

1 Like