| title | XY chart |
|---|
XY chart is used to plot points by specifying their XY coordinates.
You can also plot XY line chart by connecting the points.
See the Pen chart.xkcd XY by timqian (@timqian) on CodePen.
<script async src="https://static.codepen.io/assets/embed/ei.js"></script> const svg = document.querySelector('.xy-chart');
new chartXkcd.XY(svg, {
title: 'Pokemon farms', //optional
xLabel: 'Coordinate', //optional
yLabel: 'Count', //optional
data: {
datasets: [{
label: 'Pikachu',
data: [{ x: 3, y: 10 }, { x: 4, y: 122 }, { x: 10, y: 100 }, { x: 1, y: 2 }, { x: 2, y: 4 }],
}, {
label: 'Squirtle',
data: [{ x: 3, y: 122 }, { x: 4, y: 212 }, { x: -3, y: 100 }, { x: 1, y: 1 }, { x: 1.5, y: 12 }],
}],
},
options: { //optional
xTickCount: 5,
yTickCount: 5,
legendPosition: chartXkcd.config.positionType.upRight,
showLine: false,
timeFormat: undefined,
dotSize: 1,
},
});xTickCount: customize tick numbers you want to see on the x axis (default3)yTickCount: customize tick numbers you want to see on the y axis (default3)showLegend: display legend near chart (defaulttrue)legendPosition: specify where you want to place the legend (defaultchartXkcd.config.positionType.upLeft) Possible values:- up left:
chartXkcd.config.positionType.upLeft - up right:
chartXkcd.config.positionType.upLeft - bottom left:
chartXkcd.config.positionType.downLeft - bottom right:
chartXkcd.config.positionType.downRight
- up left:
showLine: connect the points with lines (default:false)timeFormat: specify the time format if the x values are time (defaultundefined) chart.xkcd use dayjs to format time, you can find the all the available formats heredotSize: you can change size of the dots if you want (default1)dataColors: array of colors for different datasetsfontFamily: customize font family used in the chartunxkcdify: disable xkcd effect (defaultfalse)strokeColor: stroke colors (defaultblack)backgroundColor: color for BG (defaultwhite)
Another example of XY chart: XY line chart with timeFormat
See the Pen chart.xkcd XY line by timqian (@timqian) on CodePen.
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>