Charts Integration
You can create charts using dataviewjs code blocks with the window.renderChart function.
How to Create Charts
Output a dataviewjs code block that uses window.renderChart.
Important: window.renderChart takes exactly two arguments:
- The chart data object (follows standard Chart.js format: type, data, options)
- The container element (
this.container)
Use Obsidian CSS variables (e.g., var(--interactive-accent)) for chart colors to match the theme.
Example: Bar Chart
const pages = dv.pages('#games');
const labels = pages.map(p => p.file.name).values;
const data = pages.map(p => p.rating).values;
const accentColor = getComputedStyle(document.body).getPropertyValue('--interactive-accent').trim();
const chartData = {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Game Ratings',
data: data,
backgroundColor: accentColor,
borderColor: accentColor
}]
}
}
window.renderChart(chartData, this.container);
Supported Chart Types
bar- Bar charts for comparing valuesline- Line charts for trends over timepie- Pie charts for proportionsdoughnut- Doughnut charts (pie with hole)radar- Radar charts for multi-axis comparisonpolarArea- Polar area charts
The chat interface will render the chart automatically when you output the code block.