Charts
Premium add-on. This page covers a premium add-on, included in Scriviamo Pro and Pro + Collaboration. See pricing
The premium charts add-on adds ChartNode, JSON type "chart": a chart of a table in the same
document, as bars, horizontal bars, lines, areas, a pie or a doughnut. It redraws as the table
changes, so the numbers are edited where readers can also see them.
import {ChartNode, ChartTypes} from "./dist/addons/scriviamo.charts.js"
editor.fromMarkdown("| Quarter | Revenue | Costs |\n| --- | --- | --- |\n| Q1 | 120 | 80 |\n| Q2 | 150 | 95 |")
let chart = ChartNode.create(editor) as ChartNode // draws the table above it
chart.chartType = ChartTypes.line
chart.title = "Revenue and costs"
editor.addNode(chart)
A new chart draws the nearest table above it. Choose another with Data on the chart's toolbar, or in the inspector.
How a table becomes a chart
- The first row names the series when the table has a header row, or when the first row isn't numbers.
- The first column labels the categories when it isn't numbers.
- Every other column is a series, and its cells are its values. Numbers may have thousands
separators, a currency sign or a percent sign, and accounting-style negatives such as
(10). - A column with no numbers is left out, and a cell that isn't a number leaves a gap.
With Series in Rows, each row is a series instead, and the columns are the categories.
A pie or a doughnut draws the first series.
Properties
| Property | Meaning |
|---|---|
chartType | ChartTypes.bar, horizontalBar, line, area, pie or doughnut |
sourceId | The nodeId of the table it draws, which can be a table or a data table, anywhere in the document |
title | The title drawn above the chart |
showLegend | Whether the legend shows; it only does when there's more than one series, or for a pie or doughnut |
seriesInRows | Each row is a series, rather than each column |
height | The chart's height in pixels; 320 by default |
data | The numbers drawn: {labels, series: [{name, values}]} |
ChartNode.palette holds the series' colors, in order, for every chart. svg() gives the chart as
SVG markup, and chartDataFromTable(table, seriesInRows) reads a table's numbers.
Saving and exporting
A chart is drawn as SVG, so exported HTML, PDF and print keep it, sharp at any size. The numbers it last drew are saved with it, so it still draws when its table is removed, or in a document rendered without its tables.
HTML is a <figure class="chart"> with the SVG and the chart's settings in a data-chart
attribute, which imports back as a chart. Markdown keeps the same HTML. Plain text lists each
category's values.