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 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"
[legend]="true"
[legendPosition]="'bottom'"
[legendMaxLines]="4"
[legendOtherLabel]="tr('@place_reports_products_label_other')"
[legendShowValue]="legendShowValue"
[legendValueDecimals]="legendValueDecimals"
[legendValueSuffix]="legendValueSuffix"
[height]="height">
</upp-chart>

API Reference

UppChartComponent (upp-chart)

PropertyTypeDefaultDescription
typeUppChartType'line'Chart type (bar, line, pie, doughnut).
dataUppChartData{ labels: [], datasets: [] }Chart dataset and labels through the upp-chart type contract.
optionsUppChartOptions{ responsive: true, maintainAspectRatio: false }Chart options through the upp-chart type contract.
pluginsUppChartPlugin[][]Optional chart plugins through the upp-chart type contract.
updateObservable<UppChartUpdate> | nullnullOptional stream-based updates (type, data, options, plugins).
printbooleanfalseDisables animation and enables image-ready output for print/report flows.
legendbooleanfalseEnables custom in-component legend (native Chart.js legend is hidden).
legendPositionUppChartLegendPosition'bottom'Legend position: top, bottom, left, right.
legendMaxLinesnumber0Max legend lines/items. 0 means unlimited.
legendOtherLabelstring''Label for grouped remainder when max lines is exceeded. Pass localized text from consumer.
legendOtherColorstring'rgba(152, 154, 162, 0.8)'Color for grouped remainder item.
legendShowValuebooleanfalseShows custom legend numeric values next to labels.
legendValuePrefixstring''Prefix text rendered before each custom legend value.
legendValueSuffixstring''Suffix text rendered after each custom legend value.
legendValueDecimalsnumber | nullnullFixed decimal precision for custom legend values; null keeps raw numeric rendering.
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?, exportSize?)Returns the chart as a base64 data URL (image/png or image/jpeg). If exportSize ({ width, height }) is provided, it renders offscreen at that size without touching the visible chart.
downloadImage(fileName?, format?, quality?, exportSize?)Triggers a browser download of the chart image (png/jpg). Supports optional offscreen export size ({ width, height }).

Outputs

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

Report Helpers

HelperDescription
uppChartPalette(count, alpha?)Reusable column palette used in products/clients reports.

Key-to-color mapping for domain-specific chart segments (e.g. payment methods) belongs to the consumer — see UppReportUtils.ChartColorsByKeys in feature/reports.