Files
docx/docs/usage/chart-scatter.md
T

7.4 KiB

Scatter Charts

A scatter chart plots points, each with its own x and y. Use it to show how two numbers relate, such as people's heights and weights.

Charts shows how to import ChartRun and add a chart to a document.

A Scatter Chart

new ChartRun({
    type: "scatter",
    title: "Height and weight",
    series: [
        {
            name: "Group A",
            points: [
                { x: 150, y: 50 },
                { x: 165, y: 61 },
                { x: 180, y: 75 },
            ],
        },
        {
            name: "Group B",
            points: [
                { x: 155, y: 58 },
                { x: 170, y: 72 },
            ],
        },
    ],
    xAxis: { title: "Height (cm)" },
    yAxis: { title: "Weight (kg)" },
});

A scatter chart has no categories. Instead, each series has its own points, and each point is an { x, y } pair. Series can have different numbers of points.

Markers and Lines

A scatter chart draws a circle at each point, and doesn't join them:

  • markers: false leaves out the circles.
  • lines joins each series' points, in order: "none" (the default), "straight" or "smooth".

Markers can have a shape and size, as on a line chart, and a series' line a colour, width and dash pattern. A series' own markers replace the chart's. See Markers and Lines.

series: [
    { name: "Group A", points: [{ x: 150, y: 50 }, { x: 165, y: 61 }], markers: { shape: "triangle", size: 7 } },
],

A smooth line without markers draws a curve, such as a graph of a formula:

new ChartRun({
    type: "scatter",
    series: [{ name: "y = x²", points: [-2, -1, 0, 1, 2].map((x) => ({ x, y: x * x })) }],
    markers: false,
    lines: "smooth",
});

Axes

A scatter chart has two value axes: xAxis along the bottom and yAxis up the left side. Each takes a title, a range and a number format, as a value axis does. See Chart Axes.

Options

These are all the options of a scatter chart. Each links to the page that explains it.

Property Type Notes Description
type "scatter" Required
series ScatterChartSeries[] Required { name, points, color?, markers?, line?, dataLabels?, pointLabels?, trendlines?, xErrorBars?, yErrorBars? }, where a point is { x, y }. See Chart Data Labels and Chart Trendlines and Error Bars
markers boolean | ChartMarker Optional A marker at each point. Default true
lines "none" | "straight" | "smooth" Optional How the points are joined. Default "none"
xAxis ChartValueAxis Optional The horizontal axis. See Chart Axes
yAxis ChartValueAxis Optional The vertical axis. See Chart Axes
dataLabels ChartDataLabels Optional See Chart Data Labels
title string | ChartTitle Optional See Chart Titles and Legends
legend false | ChartLegend Optional See Chart Titles and Legends
transformation { width, height } Optional See Chart Size and Position
floating IFloating Optional See Chart Size and Position
altText DocPropertiesOptions Optional See Chart Size and Position

A series' line is only for a chart whose lines join the points. A bubble chart is a scatter chart whose points have sizes. Chart Fonts and Fills shows the options every chart has for its text, background and border.