Chart.js/docs/samples/other-charts/scatter-multi-axis.md
Dan Onoshko e7372ade24
fix: same-looking tooltips on charts (#10548)
* fix: same-looking tooltips on multiseries charts

* fix: same-looknig tooltips on all chart types

* chore: restore tooltip plugin

* docs: additions to migration guide

* docs: remove labels from scatter and bubble examples

* docs: review fix
2022-08-18 07:34:35 -04:00

137 lines
3.2 KiB
Markdown

# Scatter - Multi axis
```js chart-editor
// <block:setup:1>
const DATA_COUNT = 7;
const NUMBER_CFG = {count: DATA_COUNT, rmin: 1, rmax: 1, min: -100, max: 100};
const data = {
datasets: [
{
label: 'Dataset 1',
data: Utils.bubbles(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
yAxisID: 'y',
},
{
label: 'Dataset 2',
data: Utils.bubbles(NUMBER_CFG),
borderColor: Utils.CHART_COLORS.orange,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.orange, 0.5),
yAxisID: 'y2',
}
]
};
// </block:setup>
// <block:actions:2>
const actions = [
{
name: 'Randomize',
handler(chart) {
chart.data.datasets.forEach(dataset => {
dataset.data = Utils.bubbles({count: DATA_COUNT, rmin: 1, rmax: 1, min: -100, max: 100});
});
chart.update();
}
},
{
name: 'Add Dataset',
handler(chart) {
const chartData = chart.data;
const dsColor = Utils.namedColor(chartData.datasets.length);
const newDataset = {
label: 'Dataset ' + (chartData.datasets.length + 1),
backgroundColor: Utils.transparentize(dsColor, 0.5),
borderColor: dsColor,
data: Utils.bubbles({count: DATA_COUNT, rmin: 1, rmax: 1, min: -100, max: 100}),
};
chart.data.datasets.push(newDataset);
chart.update();
}
},
{
name: 'Add Data',
handler(chart) {
const chartData = chart.data;
if (chartData.datasets.length > 0) {
for (let index = 0; index < chartData.datasets.length; ++index) {
chartData.datasets[index].data.push(Utils.bubbles({count: 1, rmin: 1, rmax: 1, min: -100, max: 100})[0]);
}
chart.update();
}
}
},
{
name: 'Remove Dataset',
handler(chart) {
chart.data.datasets.pop();
chart.update();
}
},
{
name: 'Remove Data',
handler(chart) {
chart.data.datasets.forEach(dataset => {
dataset.data.pop();
});
chart.update();
}
}
];
// </block:actions>
// <block:config:0>
const config = {
type: 'scatter',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Chart.js Scatter Multi Axis Chart'
}
},
scales: {
y: {
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
position: 'left',
ticks: {
color: Utils.CHART_COLORS.red
}
},
y2: {
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
position: 'right',
reverse: true,
ticks: {
color: Utils.CHART_COLORS.blue
},
grid: {
drawOnChartArea: false // only want the grid lines for one axis to show up
}
}
}
},
};
// </block:config>
module.exports = {
actions: actions,
config: config,
};
```
## Docs
* [Scatter](../../charts/scatter.html)
* [Cartesian Axes](../../axes/cartesian/)
* [Axis Position](../../axes/cartesian/#axis-position)