Chart component for PDF documents — renders bar, line, and pie charts.
All charts are rendered using PDF drawing primitives (rectangles, lines, arcs) with no external dependencies.
Bar chart
Pdf.Component.Chart.bar_chart(doc, {50, 500}, %{
width: 300, height: 200,
data: [
%{label: "Q1", value: 120, color: {0.2, 0.6, 0.9}},
%{label: "Q2", value: 180, color: {0.9, 0.4, 0.2}},
%{label: "Q3", value: 95, color: {0.3, 0.8, 0.4}},
%{label: "Q4", value: 210, color: {0.8, 0.2, 0.5}}
],
title: "Quarterly Revenue"
})Line chart
Pdf.Component.Chart.line_chart(doc, {50, 500}, %{
width: 300, height: 200,
series: [
%{label: "Sales", values: [10, 25, 18, 42, 35], color: {0.2, 0.5, 0.9}},
%{label: "Expenses", values: [8, 15, 22, 30, 28], color: {0.9, 0.3, 0.3}}
],
x_labels: ["Jan", "Feb", "Mar", "Apr", "May"],
title: "Monthly Trend"
})Pie chart
Pdf.Component.Chart.pie_chart(doc, {50, 500}, %{
radius: 80,
data: [
%{label: "Mobile", value: 45, color: {0.2, 0.6, 0.9}},
%{label: "Desktop", value: 35, color: {0.9, 0.4, 0.2}},
%{label: "Tablet", value: 20, color: {0.3, 0.8, 0.4}}
],
title: "Device Distribution"
})
Summary
Functions
Render a vertical bar chart.
Render a horizontal bar chart — useful for ranking or comparison data.
Render a line chart with one or more series.
Render a pie chart.
Functions
Render a vertical bar chart.
{x, y} is the top-left corner of the chart area.
Style options
:data— list of%{label: str, value: number}(required):width/:height— chart dimensions (default300×200):title— optional title above chart:show_values— display value on top of each bar (defaulttrue):show_grid— horizontal grid lines (defaulttrue):grid_lines— number of grid lines (default5):bar_gap— fraction of bar width used as gap (default0.3):bar_radius— top corner radius (default0):colors— list of colors to cycle through:axis_color/:grid_color/:text_color
Render a horizontal bar chart — useful for ranking or comparison data.
{x, y} is the top-left corner.
Style options
Same as bar_chart/3 but bars grow left-to-right.
Render a line chart with one or more series.
{x, y} is the top-left corner.
Style options
:series— list of%{label: str, values: [number], color: color}(required):x_labels— labels for the x-axis points:width/:height— chart dimensions (default300×200):title— optional title:show_dots— render dots at data points (defaulttrue):show_grid— horizontal grid lines (defaulttrue):grid_lines— number of grid lines (default5):dot_radius— radius of data point dots (default2.5):line_width— stroke width for lines (default1.5):show_legend— show legend below chart (defaulttrue)
Render a pie chart.
{x, y} is the center of the pie.
Style options
:data— list of%{label: str, value: number}(required):radius— pie radius (default80):title— optional title above:donut— inner radius fraction for donut chart (default0, set to0.5for donut):show_labels— draw labels with lines (defaulttrue):show_percentages— show % in labels (defaulttrue):colors— color cycle