# 散点图

¥Scatter Chart

散点图是在基本折线图的基础上,将 x 轴改为线性轴。要使用散点图,数据必须作为包含 X 和 Y 属性的对象传递。下面的示例创建了一个包含 4 个点的散点图。

¥Scatter charts are based on basic line charts with the x-axis changed to a linear axis. To use a scatter chart, data must be passed as objects containing X and Y properties. The example below creates a scatter chart with 4 points.

const config = {
  type: 'scatter',
  data: data,
  options: {
    scales: {
      x: {
        type: 'linear',
        position: 'bottom'
      }
    }
  }
};

# 数据集属性

¥Dataset Properties

命名空间:

¥Namespaces:

  • data.datasets[index] - 仅此数据集的选项

    ¥data.datasets[index] - options for this dataset only

  • options.datasets.scatter - 所有散点数据集的选项

    ¥options.datasets.scatter - options for all scatter datasets

  • options.elements.line - 所有 线条元素 的选项

    ¥options.elements.line - options for all line elements

  • options.elements.point - 所有 点元素 的选项

    ¥options.elements.point - options for all point elements

  • options - 整个图表的选项

    ¥options - options for the whole chart

散点图支持与 折线图 相同的所有属性。默认情况下,散点图会将折线图的 showLine 属性覆盖为 false

¥The scatter chart supports all the same properties as the line chart. By default, the scatter chart will override the showLine property of the line chart to false.

分度尺为 linear 型。这意味着,如果你使用标签数组,则值必须是数字或可解析为数字,这同样适用于键的对象格式。

¥The index scale is of the type linear. This means, if you are using the labels array, the values have to be numbers or parsable to numbers, the same applies to the object format for the keys.

# 数据结构

¥Data Structure

与可以以两种不同格式提供数据的折线图不同,散点图只接受点格式的数据。

¥Unlike the line chart where data can be supplied in two different formats, the scatter chart only accepts data in a point format.

data: [{
        x: 10,
        y: 20
    }, {
        x: 15,
        y: 10
    }]

# 内部数据格式

¥Internal data format

{x, y}