The Line dataset is the most general dataset - it can be used for line graphs, area charts, and even scatter plots
For further information on these properties, see https://www.chartjs.org/docs/latest/charts/line.html
Create a Line dataset with just a label
Set the label for this dataset
Set the data displayed by this dataset This is a list of floats, where each float is represented as a point on the line
Set the data displayed by this dataset, in a point based format This is a list of tuples, where each tuple defines the X, Y location of a point
Set whether this dataset should be hidden from the chart
Set the drawing order of the dataset This also affects stacking, tooltips, and legends
Line datasets are super easy to create - just provide a dataset label and a list of numbers:
defaultLineFromData "Dataset Label" [ 1, 2, 3, 4, 5 ]Create a Line dataset with a label and data list To create a dataset from points, see defaultLineFromPointData
You can then adjust the line styling with pipeline operators:
defaultLineFromData "Dataset Label" [ 1, 2, 3, 4, 5 ]
|> setBorderWidth 4
|> setLineTension 0.5Color of the line
Line width (in pixels)
Length and spacing of line dashes
Offset for line dashes
Cap style of the line
Joint style of the line
By default, the line will linearly connect points. You can adjust the interpolation, or set the line to produce a stepped chart instead:
Whether the line for this dataset should be drawn
Which cubic interpolation mode to use 'default' uses a weighted cubic interpolation 'monotone' is better at preserving monotonicity
Beizer curve tension 0 is straight lines
This option is ignored if cubicInterpolation is set to 'monotone'
Set the step interpolation for the line
If set to anything other than false, lineTension will be ignored
Step Interpolation for lines https://www.chartjs.org/docs/3.3.2/charts/line.html#stepped
BeforeInterpolation: Step-before Interpolation
AfterInterpolation: Step-after Interpolation
Radars are esentially a line dataset, but on a radial axis. These are slightly different internally, so you will need to create them slightly differently:
defaultRadarFromData "DatasetLabel" [ 1, 2, 3, 4, 5 ]Alternatively:
defaultLineFromData "Dataset Label" [ 1, 2, 3, 4, 5 ]
|> setLineDatasetType RadarCreate a Radar dataset with a label
Create a Radar dataset with a label
Chart.js requires the type to be specified for datasets and trying to have a line type on a radar chart causes some issues
This type allows explicitness whether this dataset is a line dataset or a radar dataset
Set the dataset type for this dataset
For most cases (yes, even scatter plots), Line works fine For radar datasets, this needs to be set to Radar
Scatter charts are essentially line charts without a line
defaultLineFromPointData "Scatter" [ ( 1, 2 ), ( 2, 5 ), ( 3, 8 ) ]
|> setShowLine FalseFor best results, you'll also want to assign a linear scale to your chart
Create a Line dataset with a label and points list
You can style the points in various ways.
Fill color for points
Border color for points
Border width (in pixels) for points
Radius of the point shape
Style of the point
Rotation of the point (in degrees)
Certain properties are used to change how points are displayed when hovered over:
Hit radius for point interactivity
Fill color for points when hovered
Border color for points when hovered
Border width for points when hovered
Radius for points when hovered
defaultLineFromData "Filled Chart" [ 1, 2, 3, 4, 5 ]
|> setFill (Boundary Origin)How to fill the area under the line
The most common use case would be filling the area under a line. For that, you'll want to use Boundary Origin:
defaultLineFromData "Title" data
|> setBackgroundColor Color.red
|> setFill (Boundary Origin)For more information, check out https://www.chartjs.org/docs/latest/charts/area.html
Fill modes handle how area charts should be displayed Can be:
Which boundary to use when using FillBoundary Can be the scale origin, start, or end
Fill color of the area under the bar Applies for area charts
See the Scale module for more information on custom axes
Which axis to use for indexing Set to XAxis for a vertical chart, set to YAxis for a horizontal chart
The ID of the X axis to plot this dataset on
The ID of the Y axis to plot this dataset on
Whether points with no data should be filled in or not
These datasets can be made from two different data formats Either a list of numbers can be specified, or a list of (x, y) tuples
See https://www.chartjs.org/docs/latest/general/data-structures.html for more info