17.2.0 • Published 22 days ago

systelab-charts v17.2.0

Weekly downloads
87
License
MIT
Repository
github
Last release
22 days ago

systelab-chart

Component to show a Chart

Using the component

<systelab-chart [labels]="labels" [data]="data" [showLegend]="legend" [(itemSelected)]="itemSelected" [type]="type"
                (action)="doAction($event)" [isBackgroundGrid]="isBackgroundGrid" [isHorizontal]="isHorizontal" [lineTension]="lineTension"
                [yMinValue]="yMinValue" [yMaxValue]="yMaxValue" [annotations]="annotations" [xLabelAxis]="xLabelAxis" [yLabelAxis]="yLabelAxis"
                [tooltipSettings]="tooltipSettings" [isStacked]="isStacked" [customLegend]="customLegend"
                [timeScale]="isTimeScaleChart"
                [timeUnit]="'month'"
                [tooltipTimeFormat]="'d, MMMM yyyy'"
></systelab-chart>

This component use the Chart.js library, and is able to display different chart types in an easy way.

Set type with the chart type that you want to display. You can choose between the following charts types

  • Bar
  • Line
  • Pie
  • Doughnut
  • Bubble
  • Radar
  • Polar Area

Also, you can show together different chart types; for example a Bar chart with Line chart. In order to do this, you should define the chart type in the properties of the data that you provide to the component.

Single example:

    this.dataLine.push(new chartItem('Only Line', [13, 20, 21, 15], '', '', false, true, false, 3));

Multiple charts example:

    this.dataLineBar.push(new chartItem('Line', [13, 20, 21, 15], '', '', false, true, true, 3, 'line'));

Properties

NameTypeDefaultDescription
labelsArraylist of labels of the chart
itemSelectedanyis used to notify which item is clicked
showLegendbooleantrueDefine the visibility of the legend
legendPositionstring'top'Define the position of the legend
intersectionSettingsChartIntersectionSettingsDefine the intersection behaviour
isBackgroundGridbooleantrueDefine if you want a grid background or not
lineTensionnumber0Define the tension of the line
yMinValueany0Min value of the axis Y
yMaxValueany0Max value of the axis Y
xMinValueany0Min value of the axis X
xMaxValueany0Max value of the axis X
xLabelAxisstring0Define the title of the Axis X
yLabelAxisstring0Define the title of the Axis Y
minValueForRadarnumber0Min value for the radar
maxValueForRadarnumber0Max value for the radar
isHorizontalbooleanfalseSet to true, if you want that display a bar chart in horizontal view
isStackedbooleanfalseSet to true, if you want that display a bar chart with stacked columns
dataArrayList of data
multipleYAxisScalesArrayList of Y axis scales
customLegendbooleanfalseDefine if you want a custom Legend (remember set legendType in chartItem)
hideInitialAndFinalTickbooleanfalseRemove the first and last tick in every axis
hideFinalTickbooleanfalseRemove the last tick in every axis
timeScalebooleanfalseDefine the chart as a time line chart
timeUnitstringdayDefine the unit that will be showed the data in Axis X (the format is the same as defined in Chart.js)
tooltipTimeFormatstringd/M/yyyyDefine the time format that will be showed in tooltips (the format is the same as defined in the date-fns)

ChartItem

NameTypeDefaultDescription
labelstringLabel name of the item
dataArrayList of values of the item
borderColorstringColor in Hexadecimal for the border
backgroundColorstringColor in Hexadecimal for the background
fillbooleantrueSet to false if you want a transparent background
showLinebooleantrueSet to false if you only want to display the area and not the border
isGradientbooleanfalseSet to true if you want to use a gradient colours
borderWidthstringDefine the width of the border
chartTypestringDefine different chart type to mix charts
chartTooltipItemChartTooltipItem or ArrayDefine what you want to display in the tooltip of this raw data or a custom tooltip for each point of this raw data.
pointRadiusnumber3The radius of the point shape. If set to 0, the point is not rendered.
yAxisIDstringDefine the ID of the y axis to plot this dataset on.
legendTypestringDefine legend type, it can be 'bar,' 'line' or 'dots'. It is only used if the customLegend property is true
labelBorderColorsArray<number[]>If the ChartItem belongs to a Doughnut, Pie or Polar Area chart, this property contains a list of colors in RGB for the border of every value and every RGB color is expressed as an array of three numbers. If not defined, a default set of colors will be used instead
labelBackgroundColorsArray<number[]>As the labelBorderColors property, but it refers to the background color of every value. Like labelBorderColors, if not defined a default set of colors will be used instead

ChartMultipleYAxisScales

NameTypeDefaultDescription
idstringY axis ID
positionstringleftAxis position
typestringChart type
gridLinesGridLineDisplay the grid lines
scaleLabelScaleLabelShow an axis label
ticksTicksDefine the values and steps for the axis

ChartIntersectionSettings

NameTypeDefaultDescription
intersectbooleanfalseEnable show tooltip only when pointer is exactly over an intersection
modestringindexThe mode for showing information

GridLine

NameTypeDefaultDescription
displaybooleantrueSet true if you want to see the grid lines
drawBorderbooleantrueSet true if you want to see a border around the grid

ScaleLabel

NameTypeDefaultDescription
displaybooleantrueShow the label
labelStringstringSet a text to be shown in the axis

Ticks

NameTypeDefaultDescription
minnumberMin value for the axis
maxnumberMax value for the axis
stepSizenumberSet the steps between axis values
displaybooleantrueSet to false if you do not want to see the ticks on the axis

Annotations

You can define two types of annotations, line or box type annotations.

annotations is an array of annotations. Depending on the annotations that you want you show, use the chartBoxAnnotation structure or chartLineAnnotation.

chartBoxAnnotation

NameTypeDefaultDescription
drawTimestringSet to draw 'afterDatasetsDraw' or 'beforeDatasetsDraw'
typestringIn this case will be 'box'
xMinnumberMin value in the axis X
xMaxnumberMax value in the axis X
yMinnumberMin value in the axis Y
yMaxnumberMax value in the axis Y
backgroundColorstringDefine the color of the box area
borderColorstringDefine the width of the border
borderWidthstringDefine the color of the box

chartLineAnnotation

NameTypeDefaultDescription
labelchartLabelAnnotationchartLabelAnnotation are the properties of the tooltip label
valuenumber/stringIf the ticks are strings and we want an annotation relative to one of this label value should be string otherwise number relative to the total ticks number
orientationstringDefine the orientation can be 'vertical' or horizontal
drawTimestringSet to draw 'afterDatasetsDraw' or 'beforeDatasetsDraw'
typestringIn this case will be 'line'
borderDashArrayIf you want a dashed line you will establish the dash properties in a number array
borderColorstringDefine the color of the box
borderWidthstringDefine the width of the border
endValuenumberDefine a end value of the line, drawing a diagonal line

chartLabelAnnotation

NameTypeDefaultDescription
textstringText of the label in the tooltip
positionstring'center', 'left' or 'right'
backgroundColorstringDefine the color of the background
fontStylestringDefine the styles of the text
fontColorstringDefine the color of the label

ChartLine

Draw a simple line

NameTypeDefaultDescription
xMinValueany0Min value of the axis X
yMinValueany0Min value of the axis Y
xMaxValueany0Max value of the axis X
yMaxValueany0Max value of the axis Y
borderColorstringblackDefine the color of the line
borderWidthstringDefine the width of the line

Tooltips

You can configure the content of the tooltips and the style.

NameTypeDefaultDescription
backgroundColorstring'rgba(0,0,0,0.8)'Tooltip background color
titleFontSizenumber12Title font size
titleFontColorstring'#ffffff'Title font color
bodyFontColorstring'#ffffff'Tooltip body font color
bodyFontSizenumber12Tooltip body font size
borderColorstring'rgba(0,0,0,0)'Tooltip border color
borderWidthnumber0Tooltip border width

ChartTooltipItem

NameTypeDefaultDescription
titlestringThe content for the title
labelnumberThe content for the body
afterLabelstringThe content that you can set after the label
valueInAfterLabelbooleantrueyou can decide where display the value, next the label (valueInAfterLabel set to false) or after the label (valueInAfterLabel set to true)
this.dataLine.push(new ChartItem('Only Line', [13, 20, 21, 15], '', '', false, true, false, 3, '',
	new ChartTooltipItem('title', 'label', 'afterlabel', true)));

Tooltips for the Bubble charts

There is the option to display the label that you want instead of the coordinates (by default defined). Set the variable t in the data parameter and the system will consider it as the tooltip label.

[{x: 13, y: 13, r: 4, t: 'Tooltip label'}, {x: 1, y: 2, r: 3}]

Chart labels

You can configure labels to show the value of the chart's datasets (e.g. the percentage of the value over the total) To do so, there is an input attribute named "chartLabelSettings" whose needs to receive a ChartLabelSettings object.

ChartLabelSettings

NameTypeDefaultDescription
positionChartLabelPositionThe settings for positioning every label
labelColorsChartLabelColorThe settings for the color of all the labels
chartLabelFontChartLabelFontThe parameters for the labels' font (font family, size, style, etc)
chartLabelPaddingChartLabelPaddingThe padding for every label
chartLabelTextChartLabelTextThe parameters for the labels' text (text align, stroke, shadow)
formatter(value: any, context: any) => stringA function that given a value and chart context returns the value as a formatted string

Example of use: let's assume that we have the following code in a component

        this.pieChartLabelSettings = new ChartLabelSettings();
this.pieChartLabelSettings.position = new ChartLabelPosition();
this.pieChartLabelSettings.position.clip = false; // to avoid showing part of the label, set clip = true

this.pieChartLabelSettings.position.display = 'auto';
this.pieChartLabelSettings.labelColors = new ChartLabelColor(undefined, 'black', undefined, 5, 1, 0.8);
const fontFamily = 'Courier, Arial Unicode MS, Arial, sans-serif';
this.pieChartLabelSettings.chartLabelFont = new ChartLabelFont(undefined, fontFamily, 16, undefined, 'bold', 0.8);
this.pieChartLabelSettings.chartLabelPadding = new ChartLabelPadding(undefined, 1, 1, 1, 1);

const myPieLabelFormatter = (value: any, context: any
):
string => {
	let dataArr: Array<number> = (context.chart.data.datasets[0].data
	as
	Array < number >
)
	;
	return (value * 100 / arraySum(dataArr)).toFixed(0) + '%';
}

this.pieChartLabelSettings.formatter = myPieLabelFormatter;

Then we can use systelab-chart with the "chartLabelSettings" attribute among others:

        <systelab-chart [labels]="labels" [data]="dataPie" [showLegend]="legend" [(itemSelected)]="itemSelected" [type]="'pie'" (action)="doAction($event)"
                        [isBackgroundGrid]="isBackgroundGrid" [chartLabelSettings]="pieChartLabelSettings"></systelab-chart>

The auxiliary classes (ChartLabelPosition, ChartLabelColor, etc) constructors are defined as follows:

ChartLabelPosition
NameTypeDefaultDescription
alignstring or number'center'The align option defines the position of the label relative to the anchor point position and orientation. Its value can be expressed either by a number representing the clockwise angle (in degree) or by one of the following string presets:
'center' (default): the label is centered on the anchor point
'start': the label is positioned before the anchor point, following the same direction
'end': the label is positioned after the anchor point, following the same direction
'right': the label is positioned to the right of the anchor point (0°)
'bottom': the label is positioned to the bottom of the anchor point (90°)
'left': the label is positioned to the left of the anchor point (180°)
'top': the label is positioned to the top of the anchor point (270°)
a number: the label is positioned to the specified number of grades relative to the anchor. E.g. 90 is equivalent to 'bottom', 45 in the "middle" between 'bottom' and 'right'
anchorstring'center'An anchor point is defined by an orientation vector and a position on the data element. The orientation depends on the scale type (vertical, horizontal or radial). The position is calculated based on the anchor option and the orientation vector.
'center' (default): label's anchor is centered on the element's boundary that the label represents
'start' : label's anchor is positioned in the lowest boundary of the element that the label represents
'end' : label's anchor is positioned in the highest boundary of the element that the label represents
clampbooleanfalseThe clamp option, when true, enforces the anchor position to be calculated based on the visible geometry of the associated element (i.e. part inside the chart area)
clipbooleanfalseWhen the clip option is true, the part of the label which is outside the chart area will be masked
display((context: any) => (boolean or string)) or booleantrueThe display option controls the visibility of labels and accepts the following values:
true (default): the label is drawn
false : the label is hidden
'auto' : the label is hidden if it overlap with another label
This option is scriptable, so it's possible to show/hide specific labels: see example below
offsetnumber4The offset represents the distance (in pixels) to pull the label away from the anchor point. This option is not applicable when align is 'center'. Also note that if align is 'start', the label is moved in the opposite direction.
rotationnumber0This option controls the clockwise rotation angle (in degrees) of the label, the rotation center point being the label center.

Example of specifiying the "display" property as a function:

const displayFunction = (context: any)
:
boolean => {

	let dataArr: Array<number> = (context.chart.data.datasets[0].data
	as
	Array < number >
)
	;

	const currentPercentage = context.dataset.data[context.dataIndex] * 100 / arraySum(dataArr);

	return currentPercentage >= 5;
}
this.pieChartLabelSettings.position.display = displayFunction;
ChartLabelColor
NameTypeDefaultDescription
backgroundColorstringnullThe background color for every label. It accepts names, hexadecimal values and rgb definitions. E.g.: 'white', '#778899', 'rgb(0,255,0)'. If not defined, the background does not take any color
colorstring'#666'The color for the text in every label. It accepts names, hexadecimal values and rgb definitions, too.
borderColorstringnullThe color for every label's border. Again, it accepts names, hexadecimal values and rgb definitions. If not defined, the border is not visible
borderRadiusnumber0The radius of every label's border. A value bigger than zero makes the label's border corner being rounded.
borderWidthnumber0The width of the label's borders. If it's value is undefined or zero, the border is not shown.
opacitynumber1Defines the opacity of the label's text. Values go from 0 to 1, including decimals (for example 0.5) A value of zero makes the text invisible
ChartLabelFont
NameTypeDefaultDescription
fontobjectnullAn object that can be used as a shorthand to specify the family, size, style, weight and lineHeight parameters, see object's definition below. Usually, if this parameter is defined the rest of the parameters, family, size, etc are set as undefined. But if they don't, their values will substituted the ones defined in "font"
familystring"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"Font family for the text of all the labels
sizenumber12Labels' font size
stylestring'normal'Labels' font style. The possible values are 'italic', 'oblique' and 'normal'
weightstring or number'normal'Labels' font weight. The possible values are 'bold', 'bolder', 'lighter', 'normal' and a number (e.g. 100, 200, etc
lineHeightstring or number1.2Defines the space between each line in the labels' text (if the need more than one line)

Definition of the font parameter as an object:

type
Font = {
	family    ? : string,
	lineHeight? : string | number,
	size      ? : number,
	style     ? : 'normal' | 'italic' | 'oblique',
	weight    ? : 'normal' | 'bold' | 'bolder' | 'lighter' | number
};
ChartLabelPadding
NameTypeDefaultDescription
paddingnumber or objectundefinedIf used as a number, it specifies the padding for the top, right, bottom and left padding of the labels' text. If used as an object, it has to defined as a shorthand of the 4 properties, see the definition of the object below
topnumber4The top padding for the labels' text
rightnumber4The right padding for the labels' text
bottomnumber4The bottom padding for the labels' text
leftnumber4The left padding for the labels' text

Definition of the padding parameter as an object:

type
Padding = number | {
	top?: number,
	right?: number,
	bottom?: number,
	left?: number
};
ChartLabelText
NameTypeDefaultDescription
textAlignstring'start'The textAlign option only applies to multiline labels and specifies the text alignment being used when drawing the label text
Supported values are:
'start' (default): the text is left-aligned
'center': the text is centered
'end': the text is right-aligned
'left': alias of 'start'
'right': alias of 'end'
textStrokeColorstringnullColor for the labels' text stroke
textStrokeWidthnumbernullWidth of the labels' text stroke
textShadowBlurnumbernullBlur of the labels' text stroke
textShadowColorstringnullColor for the labels' text shadow
ChartMeterConfiguration
NameTypeDefaultDescription
borderColorstring'#007bff'The border color applied to the graph
numberFormatstringThe number format to apply the values
chartColourstringThe color for the bars in the history chart
goalColourstringThe color for the goal values in the history chart
betterValuesstringPending description
Supported values are:
'higher' (default): the higher values are the better ones
'lower' : the lower values are the better ones
markerForGoalstringThe marker for the goal value in the history chart
Supported values are:
'circle' (default), 'cross', 'crossRot', 'dash', 'line', 'rect', 'rectRounded', 'rectRot', 'star', 'triangle'
defaultGoalValuenumberThe default goal value in case that there's no list of goal values
minVisualValuenumberValue as a lower limit in the graphs. If not informed the min value will be de lower value in the dataset
maxVisualValuenumberValue as a higher limit in the graphs. If not informed the max value will be de lower value in the dataset
showHistorybooleanfalseShow the history graph by default
levelsobjectList of levels to be included in the graphs

Definition of a level parameter as an object:

type
Levels = {
	levelColor: string,
	minValue:   number,
	maxValue:   number
};

Events

NameParametersDescription
doUpdateReset the chart with the new data.
actionIs going to emit the event when you clicked in a item in the chart

Functions

NameParametersDescription
getResizedBase64Imagenumber?, number?Get the base64 png string image scaled based on the height and width parameters (if provided).
doResizeChartstring, stringPerform a chart resize based on the height and width parameters (in pixels).

Note: responsive and maintainAspectRatio parameters must be set to false.

17.2.0

22 days ago

17.1.4

2 months ago

17.1.2

2 months ago

17.1.3

2 months ago

17.1.1

2 months ago

17.1.1-beta

3 months ago

17.1.0

4 months ago

17.0.0

4 months ago

16.0.1

7 months ago

15.3.0

10 months ago

15.2.0

11 months ago

15.1.1

1 year ago

15.1.2

1 year ago

15.1.0

1 year ago

15.0.0

1 year ago

14.0.0

2 years ago

14.0.1

2 years ago

9.7.1

2 years ago

9.7.0

2 years ago

9.5.0

2 years ago

9.4.0

2 years ago

9.2.0

2 years ago

9.1.1

3 years ago

9.1.0

3 years ago

9.0.0

3 years ago

7.1.4

3 years ago

8.0.2

3 years ago

7.1.3

3 years ago

7.1.2

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.3

3 years ago

8.0.0

3 years ago

7.0.1

3 years ago

7.0.0

3 years ago

6.2.0

4 years ago

6.1.0

4 years ago

6.0.3

4 years ago

6.0.4

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.4.0

4 years ago

5.3.0

4 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.0.1

5 years ago

4.3.1

5 years ago

5.0.0

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.4.0

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago