Chart | AIUI | Rokid

Use chart to display array data as a line, area, bar, scatter, pie, radar, or funnel chart. You provide the data and chart type instead of drawing the result manually wit…

Chart

Use chart to display array data as a line, area, bar, scatter, pie, radar, or funnel chart. You provide the data and chart type instead of drawing the result manually with Canvas.

Draw Your First Chart

This line chart reads the value field from each data item:

<chart
  class="trend-chart"
  type="line"
  series="value"
  data="{{chartData}}"
></chart>
export default {
  data: {
    chartData: [
      { label: 'Mon', value: 120 },
      { label: 'Tue', value: 168 },
      { label: 'Wed', value: 142 },
      { label: 'Thu', value: 196 }
    ]
  }
};
.trend-chart {
  width: 350px;
  height: 180px;
}

data accepts an array. series="value" tells the chart to use the value field from each item. Set the chart size with CSS rather than chart-specific width and height properties.

Choose a Chart Type

What you want to showRecommended charttype value
Change over timeLine or arealine, area
Values across categoriesBarbar
Distribution between two valuesScatterscatter
Parts of a wholePiepie
Several dimensionsRadarradar
Values across process stagesFunnelfunnel

Change type to switch the basic chart type:

<chart type="bar" series="value" data="{{chartData}}"></chart>

Display Multiple Series

When one chart needs several data series, set series to a JSON array. Each item needs at least a yName for the numeric field. xName identifies the horizontal-axis field.

<chart
  type="line"
  data="{{weatherData}}"
  series='[
    {"xName":"day","yName":"high","color":"#ff6b6b","smooth":true},
    {"xName":"day","yName":"low","color":"#4dabf7","smooth":true}
  ]'
></chart>
export default {
  data: {
    weatherData: [
      { day: 'Mon', high: 26, low: 18 },
      { day: 'Tue', high: 28, low: 19 },
      { day: 'Wed', high: 25, low: 17 }
    ]
  }
};

Each series may also provide its own array through dataSource, and use width to set its line width.

Show a Horizontal Bar Chart with Values

Bars are vertical by default. Set direction="horizontal" when category names are long and need more room.

<chart
  type="bar"
  direction="horizontal"
  series="value"
  data="{{ranking}}"
  show-value-labels="true"
></chart>

show-value-labels displays each value next to its shape. Use value-label-format to format the text, for example percent for a percentage or compact for abbreviated large values.

Configure the Axes

x-axis and y-axis accept JSON objects. Common settings include the title, minimum and maximum values, labels, and grid lines.

<chart
  type="line"
  data="{{chartData}}"
  series='[{"xName":"label","yName":"value"}]'
  x-axis='{"title":"Date","showGridLines":false}'
  y-axis='{"title":"Requests","minimum":0,"showGridLines":true}'
></chart>

When axis settings are omitted, the component chooses defaults from the data. Beginners usually do not need to configure the axes immediately.

Common Properties

PropertyTypeDefaultDescription
typeStringlineline, area, bar, scatter, pie, radar, or funnel.
dataArray[]Data array used by the chart.
seriesString / JSON ArrayvalueNumeric field name or a multiple-series configuration.
colorStringTheme colorMain color for a single series.
animateBooleanfalseWhether to animate the initial drawing and data changes.
smoothBooleantrueWhether line and area charts use smooth curves.
show-averageBooleanfalseWhether line and area charts show a dashed average line. showAverage is also accepted.
directionStringverticalBar direction: vertical or horizontal.
show-value-labelsBooleanfalseWhether values are shown next to their shapes. showValueLabels is also accepted.
value-label-formatString-Value text format: number, grouped, percent, compact, integer, or datetime. valueLabelFormat is also accepted.
value-label-colorStringTheme text colorValue text color. valueLabelColor is also accepted.
x-axisJSON ObjectDefault x-axisHorizontal-axis settings. xAxis is also accepted.
y-axisJSON ObjectDefault y-axisVertical-axis settings. yAxis is also accepted.

Properties for Specific Chart Types

These properties only affect the listed chart types. Ignore them when they are not needed.

ChartPropertyDefaultDescription
Scatter, radarpoint-size4Point size. pointSize is also accepted.
Scatter, radarpoint-colorTheme colorPoint color. pointColor is also accepted.
Pieshow-percentagefalseWhether percentages are displayed. showPercentage is also accepted.
Piemax-disk-diameter-Maximum pie disk diameter. maxDiskDiameter is also accepted.
Piemin-radius-Minimum pie radius. minRadius is also accepted.
Radar, funnellabel-key-Data field used as the item name. labelKey is also accepted.
Funnelvalue-key-Data field used as the numeric value. valueKey is also accepted.
RadarlevelsTheme defaultNumber of grid levels.
Radarshow-pointsTheme defaultWhether data points are displayed. showPoints is also accepted.
RadarmaxCalculatedMaximum radar value.
Funnelshow-conversiontrueWhether stage conversion rates are displayed. showConversion is also accepted.
Funnelfunnel-conversion-key-Data field containing a precomputed conversion rate. funnelConversionKey is also accepted.
Funnelfunnel-conversion-title转化率Conversion-rate title. funnelConversionTitle is also accepted.

Charts also read color, line, and text settings from the current theme. Start with the defaults, then override colors such as color, label-color, grid-color, or fill-color only when the visual design requires it.

series Configuration

FieldTypeRequiredDescription
yNameStringYesNumeric field name. yKey is also accepted.
xNameStringNoHorizontal-axis field name. xKey is also accepted.
dataSourceArrayNoSeparate data array for this series.
colorStringNoColor for this series.
widthNumberNoLine width.
smoothBooleanNoWhether this line is smooth.

Axis Configuration

Both x-axis and y-axis support these common fields:

FieldTypeDescription
minimum / maximumNumberMinimum and maximum axis values. y-axis also accepts min and max.
showAxisLineBooleanWhether the axis line is visible.
showGridLinesBooleanWhether grid lines are visible.
showLabelsBooleanWhether labels are visible.
showTicksBooleanWhether tick marks are visible.
tickCountNumberPreferred number of ticks.
tickLengthNumberLength of each tick mark.
titleStringAxis title.
labelFormatStringLabel format. format is also accepted.
opposedPositionBooleanWhether the axis appears on the opposite side.

y-axis additionally supports interval and stripLines. x-axis additionally supports valueType and intervalType.

Bar-chart value labels

Vertical bar charts also support show-value-labels="true". Use value-label-format and value-label-color to format values. Labels follow bar positions and data animation without changing the bar color.