Modules@robinpath/chart
chart

@robinpath/chart

0.1.2Node.jsPublic

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.

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.create to perform this operation
  • Add a dataset to an existing chart -- Use chart.addDataset to perform this operation
  • Update chart options (title, size, legend, type, labels) -- Use chart.update to perform this operation
  • Render chart and save to PNG or JPEG file -- Use chart.save to perform this operation
  • Render chart and return as base64 data URL string -- Use chart.toBase64 to perform this operation

Quick Reference

FunctionDescriptionReturns
createCreate a new chart (bar, line, pie, doughnut, scatter, radar, polarArea, bubble)Chart creation info
addDatasetAdd a dataset to an existing chartUpdated dataset count
updateUpdate chart options (title, size, legend, type, labels)Update confirmation
saveRender chart and save to PNG or JPEG fileSave result with file size
toBase64Render chart and return as base64 data URL stringBase64 data URL (data:image/png;base64,...)
toBufferRender chart and return as raw BufferPNG buffer
destroyRemove chart from memoryDestroy 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"}
ParameterTypeRequiredDescription
idstringYesUnique chart identifier
typestringYesChart type: bar, line, pie, doughnut, scatter, radar, polarArea, bubble
dataobjectYes{labels: string[], datasets: [{label, data, backgroundColor?, borderColor?}]}
optsobjectNo{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]}
ParameterTypeRequiredDescription
idstringYesChart ID
datasetobjectYes{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}
ParameterTypeRequiredDescription
idstringYesChart ID
optsobjectYes{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"
ParameterTypeRequiredDescription
idstringYesChart ID
filePathstringYesOutput file path
optsobjectNo{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"
ParameterTypeRequiredDescription
idstringYesChart ID
optsobjectNo{format?: 'png'

toBuffer

Render chart and return as raw Buffer

Module: chart | Returns: object -- PNG buffer

chart.toBuffer "c1"
ParameterTypeRequiredDescription
idstringYesChart ID

destroy

Remove chart from memory

Module: chart | Returns: object -- Destroy confirmation

chart.destroy "c1"
ParameterTypeRequiredDescription
idstringYesChart ID

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Chart "..." not foundCheck the error message for details
Chart "..." already existsCheck 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)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/chart

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size5.8 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

data