Create charts and visualizations from note data using Chart.js via dataviewjs. Use when user wants bar charts, line graphs, pie charts, or any data visualization. Requires Obsidian Charts plugin.
You can create charts using dataviewjs code blocks with the window.renderChart function.
Output a dataviewjs code block that uses window.renderChart.
Important: window.renderChart takes exactly two arguments:
this.container)Use Obsidian CSS variables (e.g., var(--interactive-accent)) for chart colors to match the theme.
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);
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 chartsThe chat interface will render the chart automatically when you output the code block.