Skip to main content

upp-chart

upp-chart is a lightweight wrapper around Chart.js for upp-wdgt. It handles instance lifecycle (create, update, destroy) and exposes a simple Angular API based on reactive inputs.

It also includes report-oriented support:

  • stream updates through an Observable (update)
  • print mode with ready image output (print + ready)
  • reusable palette and options helpers for report charts.

When to Use

  • You need charts in feature views but want a reusable UPP widget.
  • You want Chart.js rendering with Angular input bindings.
  • You want to update data/type without manual canvas management.
  • You need to export chart images (png/jpg) for reports.

Demo

Source Code

<ion-button size="small" (click)="exportPng()">Export PNG</ion-button>
<ion-button size="small" (click)="exportJpg()">Export JPG</ion-button>
<ion-button size="small" (click)="setType('pie')">Pie</ion-button>
<ion-button size="small" (click)="setType('doughnut')">Doughnut</ion-button>

<upp-chart
[type]="type"
[data]="data"
[options]="options"
[customLegend]="true"
[customLegendPosition]="'bottom'"
[customLegendMaxLines]="4"
[customLegendOtherLabel]="tr('@place_reports_products_label_other')"
[height]="height">
</upp-chart>

API Reference

UppChartComponent (upp-chart)

PropertyTypeDefaultDescription
typeUppChartType'line'Chart type (bar, line, pie, doughnut).
dataChartData{ labels: [], datasets: [] }Chart.js dataset and labels.
optionsChartOptions{ responsive: true, maintainAspectRatio: false }Chart.js options for axes, legend, tooltips, and behavior.
pluginsPlugin[][]Optional Chart.js plugins for this chart instance.
updateObservable<UppChartUpdate> | nullnullOptional stream-based updates (type, data, options, plugins).
printbooleanfalseDisables animation and enables image-ready output for print/report flows.
customLegendbooleanfalseEnables custom in-component legend (native Chart.js legend is hidden).
customLegendPositionUppChartLegendPosition'bottom'Legend position: top, bottom, left, right.
customLegendMaxLinesnumber0Max legend lines/items. 0 means unlimited.
customLegendOtherLabelstring''Label for grouped remainder when max lines is exceeded. Pass localized text from consumer.
customLegendOtherColorstring'rgba(152, 154, 162, 0.8)'Color for grouped remainder item.
widthstring'100%'CSS width of the host component.
heightstring'260px'CSS height of the chart area.

Methods

MethodDescription
refresh()Recreates the underlying Chart.js instance with the current inputs.
getImageDataUrl(format?, quality?)Returns the chart as a base64 data URL (image/png or image/jpeg).
downloadImage(fileName?, format?, quality?)Triggers a browser download of the chart image (png/jpg).

Outputs

OutputTypeDescription
readyEventEmitter<string>Emits PNG data URL when the chart is rendered in print mode.

Report Helpers

HelperDescription
UPP_CHART_REPORT_OPTIONSBase options for report-style charts (legend bottom + maintainAspectRatio:false).
uppChartBuildGooglePalette(count, alpha?)Reusable column palette used in products/clients reports.
uppChartBuildMappedPalette(keys, colorMap, fallbackColor?)Generic key-to-color palette helper with fallback color.