Q2 Chart Area

Updated:

Documentation

Chart Data

The chart data is an array of objects that are set on the data property of the q2-chart-area component. Each object must have an id, name, and value property.

Data Structure

type Data = { 
  id: string; 
  value: number; 
  name: string;
};

Example

const chart = document.querySelector("q2-chart-area");
chart.data = [
  {
    value: 45,
    name: 'Sun',
    id: 'sunday',
  },
  {
    value: 36,
    name: 'Mon',
    id: 'monday',
  },
  {
    value: 62,
    name: 'Tue',
    id: 'tuesday',
  },
  {
    value: 51,
    name: 'Wed',
    id: 'wednesday',
  },
  {
    value: 104,
    name: 'Thu',
    id: 'thursday',
  },
  {
    value: 122,
    name: 'Fri',
    id: 'friday',
  },
  {
    value: 215,
    name: 'Sat',
    id: 'saturday',
  }
]

Attributes API

The q2-chart-area element has several properties that support text localization. Those properties are indicated by the localizable badge below.

PropertyAttributeTypeDefaultDescription
alignChartNamealignChartNamestringleft

Controls alignment of chart name when visible.

Type

type alignChartName = "left" | "center" | "right";

Example

element.alignChartName = "center";
areaColorarea-colorstringvar(--t-primary)

Controls area fill color of chart. Accepts variables, hex. and CSS color names.

Examples

element.areaColor = "#ff0000";
element.areaColor = "papayawhip";
element.areaColor = "var(--t-accent-1)";
chartNamechart-namestring
Localizable

Name of the chart. Hidden by default, but can be made visible with the showChartName property.

Example

element.chartName = "Weekly spending";
dataNamesOverflowdata-names-overflowstring

Allows control of how labels on the name axis will be handled if the text length is wider than the available space. Values will ellipsize when the truncate option is used.

Type

type dataNamesOverflow = "break" | "truncate";

Example

element.dataNamesOverflow = "truncate";
dataNamesWidthdata-names-widthnumber50

Sets width available for labels on the name axis. It can be used in coordination with dataNamesOverflow to control where the label text breaks and truncates.

Example

element.dataNamesWidth = 75;
formatformatstringdefault

Controls whether values on the chart and axis are shown as numbers or as currency.

Type

type format = "default" | "currency";

Example

element.format = "currency";
formatModifierformat-modifierstring

Can be used in coordination with the currency format property to control decimal handling. Accepts Ndec where N is a number. (e.g. 2dec)

Example

element.formatModifier = "2dec";
gridLinesgrid-linesstringhorizontal

Controls the direction or visibility of grid lines on the chart.

Type

type gridLines = "horizontal" | "vertical" | "off";

Example

element.gridLines = "vertical";
hideNameAxisLabelshide-name-axis-labelsbooleanfalse

Controls visibility of labels on the name axis.

Example

element.hideNameAxisLabels = true;
hideValueAxisLabelshide-value-axis-labelsbooleanfalse

Controls visibility of labels on the value axis.

Example

element.hideValueAxisLabels = true;
lineColorline-colorstringvar(--t-primary)

Controls color of data line on chart. Accepts variables, hex. and CSS color names.

Examples

element.lineColor = "#ff0000";
element.lineColor = "papayawhip";
element.lineColor = "var(--t-accent-1)";
offsetDataNamesoffset-data-namesbooleanfalse

Controls position of text on the names axis. When true, will center text to bar on a 45° angle. Can be used when space is limited or with longer name labels.

Example

element.offsetDataNames = true;
offsetDataValuesoffset-data-valuesbooleanfalse

Controls position of text on the values axis. When true, will center text to bar on a 45° angle. Can be used when space is limited or with longer name labels.

Example

element.offsetDataValues = true;
pointerLineColorpointer-line-colorstringvar(--t-gray-10)

Controls color of vertical pointer line on chart. Accepts variables, hex. and CSS color names.

Examples

element.pointerLineColor = "#ff0000";
element.pointerLineColor = "papayawhip";
element.pointerLineColor = "var(--t-accent-1)";
type FormatValues = "default" | "currency";

Example

element.format = "currency";
pointerLineStylepointer-line-stylestringsolid

Controls style of vertical pointer line on chart.

Type

type pointerLineStyle = "solid" | "dashed";

Example

element.pointerLineStyle = "dashed";
showChartNameshow-chart-namebooleanfalse

Controls visibility of the chart name at the top of the chart.

Example

element.showChartName = "true";
showDatapointLabelsshow-datapoint-labelsbooleanfalse

Controls visibility of a value label when a data point is shown on the chart.

Example

element.showDatapointLabels = "true";
showGradientshow-gradientbooleanfalse

Controls making the area fill color, set via areaColor, into a gradient. The gradient starts at the top with the areaColor and fades to white.

Example

element.showGradient = "true";

Events API

The q2-chart-area element exposes events that can be used to send and receive data from the component.

EventDetails
change

Emitted when the pointer line is aligned with a data point on the chart. Returns index and data item from passed data array.

Type

type ChangeEvent = CustomEvent<{
  index: number;
  data: Data
}>;

Example

element.onchange = (event) => {
  console.log(`The pointer line and data point is aligned with ${event.detail.data.name} with the value of ${event.detail.data.value}. This data item is in position ${event.detail.index} of the data array.`);
}

The lists below contain references to all the CSS variables available for use in the q2-chart-area component.

The following CSS variables are available to override the default theme styles of the q2-chart-areacomponent.

    The following CSS variables are used by the q2-chart-area component and available for theming.