/*
* LightningChartJS example that showcases PointSeries in a 3D Chart.
*/
// Import LightningChartJS
const lcjs = require('@arction/lcjs')
// Import xydata
const xydata = require('@arction/xydata')
// Extract required parts from LightningChartJS.
const { lightningChart, SolidFill, ColorRGBA, PointStyle3D, Themes } = lcjs
// Extract required parts from xyData.
const { createWaterDropDataGenerator } = xydata
// Initiate chart
const chart3D = lightningChart()
.Chart3D({
// theme: Themes.darkGold
})
.setTitle('3D Scatter Chart')
// Set Axis titles
chart3D.getDefaultAxisX().setTitle('Axis X')
chart3D.getDefaultAxisY().setTitle('Axis Y')
chart3D.getDefaultAxisZ().setTitle('Axis Z')
// Create Point Series for rendering max Y coords.
const pointSeriesMaxCoords = chart3D.addPointSeries().setName('Max coords')
pointSeriesMaxCoords.setPointStyle(
new PointStyle3D.Triangulated({
fillStyle: pointSeriesMaxCoords.getPointStyle().getFillStyle(),
size: 10,
shape: 'sphere',
}),
)
// Create another Point Series for rendering other Y coords than Max.
const pointSeriesOtherCoords = chart3D.addPointSeries({ automaticColorIndex: 2 }).setName('Below Max')
pointSeriesOtherCoords.setPointStyle(
new PointStyle3D.Triangulated({
fillStyle: pointSeriesOtherCoords.getPointStyle().getFillStyle(),
size: 5,
shape: 'cube',
}),
)
// Add LegendBox to chart.
chart3D
.addLegendBox()
// Dispose example UI elements automatically if they take too much space. This is to avoid bad UI on mobile / etc. devices.
.setAutoDispose({
type: 'max-width',
maxWidth: 0.3,
})
.add(chart3D)
// Generate heatmap data for depicting amount of scattered points along the XZ plane.
let totalPointsAmount = 0
const rows = 40
const columns = 60
createWaterDropDataGenerator()
.setRows(rows)
.setColumns(columns)
.generate()
.then((data) => {
// 'data' is a number Matrix number[][], that can be read as data[row][column].
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const value = data[row][column]
// Generate 'value' amount of points along this XZ coordinate,
// with the Y coordinate range based on 'value'.
const pointsAmount = Math.ceil(value / 100)
const yMin = 0
const yMax = value
for (let iPoint = 0; iPoint < pointsAmount; iPoint++) {
const y = yMin + Math.random() * (yMax - yMin)
pointSeriesOtherCoords.add({ x: row, z: column, y })
totalPointsAmount++
}
pointSeriesMaxCoords.add({ x: row, z: column, y: yMax })
totalPointsAmount++
}
}
chart3D.setTitle(chart3D.getTitle() + ` (${totalPointsAmount} data points)`)
// Set explicit Y Axis interval.
chart3D.getDefaultAxisY().setInterval({ start: 0, end: 150, animate: 2000 })
})
Also known as a Scatter Graph, Scatter Series, Point Graph, Scatter diagram or Scattergram
This example shows a simple 3D Point Graph with points drawn using 3D PointSeries for a visual representation of the data points 'markers'. The point graph is a type of chart or mathematical diagram drawn on a Cartesian coordinate system and represents the relationship between two variables.
This type of series does not contain the visual representation of lines for the connection of data points but only data 'markers'.
The chart can be created with few simple lines of code:
// Create a new ChartXY.const chart3D =lightningChart().Chart3D()// Add a line series using default X, Y and Z axes.const series = chart3D.addPointSeries()
The series accepts points in format { x: number, y: number, z:number }. Any number of points can be added with a single call.