@robinpath/chart
0.1.2Node.jsPublicGenerate chart images (PNG/JPEG) using Chart.js. Supports bar, line, pie, doughnut, scatter, radar, polarArea, and bubble charts with auto-coloring and customizable titles, legends, and dimensions.
Chart
Generate chart images (PNG/JPEG) using Chart.js. Supports bar, line, pie, doughnut, scatter, radar, polarArea, and bubble charts with auto-coloring and customizable titles, legends, and dimensions.
Package: @robinpath/chart | Category: Analytics | Type: Integration
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the chart module when you need to:
- Create a new chart (bar, line, pie, doughnut, scatter, radar, polarArea, bubble) -- Use
chart.createto perform this operation - Add a dataset to an existing chart -- Use
chart.addDatasetto perform this operation - Update chart options (title, size, legend, type, labels) -- Use
chart.updateto perform this operation - Render chart and save to PNG or JPEG file -- Use
chart.saveto perform this operation - Render chart and return as base64 data URL string -- Use
chart.toBase64to perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
create | Create a new chart (bar, line, pie, doughnut, scatter, radar, polarArea, bubble) | Chart creation info |
addDataset | Add a dataset to an existing chart | Updated dataset count |
update | Update chart options (title, size, legend, type, labels) | Update confirmation |
save | Render chart and save to PNG or JPEG file | Save result with file size |
toBase64 | Render chart and return as base64 data URL string | Base64 data URL (data:image/png;base64,...) |
toBuffer | Render chart and return as raw Buffer | PNG buffer |
destroy | Remove chart from memory | Destroy confirmation |
Functions
create
Create a new chart (bar, line, pie, doughnut, scatter, radar, polarArea, bubble)
Module: chart | Returns: object -- Chart creation info
chart.create "c1" "bar" {"labels": ["Q1","Q2"], "datasets": [{"label": "Sales", "data": [100,200]}]} {"title": "Revenue"}
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique chart identifier |
type | string | Yes | Chart type: bar, line, pie, doughnut, scatter, radar, polarArea, bubble |
data | object | Yes | {labels: string[], datasets: [{label, data, backgroundColor?, borderColor?}]} |
opts | object | No | {width?, height?, title?, backgroundColor?, indexAxis?, legendPosition?, showLegend?} |
addDataset
Add a dataset to an existing chart
Module: chart | Returns: object -- Updated dataset count
chart.addDataset "c1" {"label": "Costs", "data": [50, 80]}
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chart ID |
dataset | object | Yes | {label, data, backgroundColor?, borderColor?, borderWidth?} |
update
Update chart options (title, size, legend, type, labels)
Module: chart | Returns: object -- Update confirmation
chart.update "c1" {"title": "Updated Title", "width": 1200}
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chart ID |
opts | object | Yes | {title?, width?, height?, backgroundColor?, type?, legendPosition?, showLegend?, labels?} |
save
Render chart and save to PNG or JPEG file
Module: chart | Returns: object -- Save result with file size
chart.save "c1" "./output/chart.png"
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chart ID |
filePath | string | Yes | Output file path |
opts | object | No | {format?: 'png' |
toBase64
Render chart and return as base64 data URL string
Module: chart | Returns: string -- Base64 data URL (data:image/png;base64,...)
chart.toBase64 "c1"
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chart ID |
opts | object | No | {format?: 'png' |
toBuffer
Render chart and return as raw Buffer
Module: chart | Returns: object -- PNG buffer
chart.toBuffer "c1"
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chart ID |
destroy
Remove chart from memory
Module: chart | Returns: object -- Destroy confirmation
chart.destroy "c1"
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chart ID |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
Chart "..." not found | Check the error message for details |
Chart "..." already exists | Check the error message for details |
@desc "Create and validate result"
do
set $result as chart.create "c1" "bar" {"labels": ["Q1","Q2"], "datasets": [{"label": "Sales", "data": [100,200]}]} {"title": "Revenue"}
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. Create a new item with create
Create a new resource and capture the result.
set $result as chart.create "c1" "bar" {"labels": ["Q1","Q2"], "datasets": [{"label": "Sales", "data": [100,200]}]} {"title": "Revenue"}
print "Created: " + $result
2. Create and update workflow
Create an item and then update it.
@desc "Create and update"
do
set $created as chart.create "c1" "bar" {"labels": ["Q1","Q2"], "datasets": [{"label": "Sales", "data": [100,200]}]} {"title": "Revenue"}
# Update the created item
chart.update "c1" {"title": "Updated Title", "width": 1200}
enddo
3. Multi-step Chart workflow
Chain multiple chart operations together.
@desc "Create, add dataset, and more"
do
set $r_create as chart.create "c1" "bar" {"labels": ["Q1","Q2"], "datasets": [{"label": "Sales", "data": [100,200]}]} {"title": "Revenue"}
set $r_addDataset as chart.addDataset "c1" {"label": "Costs", "data": [50, 80]}
set $r_update as chart.update "c1" {"title": "Updated Title", "width": 1200}
print "All operations complete"
enddo
4. Safe create with validation
Check results before proceeding.
@desc "Create and validate result"
do
set $result as chart.create "c1" "bar" {"labels": ["Q1","Q2"], "datasets": [{"label": "Sales", "data": [100,200]}]} {"title": "Revenue"}
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.2 | latest | 1 months ago |
Related Modules
firebase
JS@robinpathv0.1.1
Firebase module for RobinPath.
graph
JS@robinpathv0.1.1
Graph data structures with BFS, DFS, Dijkstra's shortest path, topological sort, cycle detection, and connectivity
hotjar
JS@robinpathv0.1.1
Hotjar module for RobinPath.
mixpanel
JS@robinpathv0.1.2
Mixpanel module for RobinPath.
$ robinpath add @robinpath/chart
