Options configuration for line charts

The same general options we used for bar charts can be used to configure line charts, but there are some chart specific options, too. All charts come preconfigured with defaults, which can be overridden using local or global properties. One of the ways to remove the shading for all charts that use lines (instead of setting transparency per dataset) is to declare the fill global property for line elements as false, as follows:

Chart.defaults.global.elements.line.fill = false;

However, you can configure options per-chart setting properties in the options configuration object. We improved the way our first line chart was rendered, removing the legend, which is not necessary as there is only one dataset (see LineArea/line-2.html), as follows:

let chartObj = {
type: "line",
data: dataObj,
options:{
legend: {
display: false
}
}
};
new Chart("my-line-chart", chartObj);

Data points can be completely hidden by setting pointRadius to zero in each dataset. However, you can also configure them for all datasets and charts globally by setting the values of the properties in Chart.defaults.global.elements.point.radius. This hides all points from all charts that use points, as follows:

Chart.defaults.global.elements.point.radius = 0;

If you have a very large number of points, you may not want to draw the lines. To hide the line of a specific dataset, you can set its showLine property to false, but you can also configure line drawing for all lines with the options properties listed as follows.

They can be set locally for the current chart or globally for all charts:

Property

Value

Description

showLines

true or false

If this property is false, the lines between the points are not drawn. The default for line charts is true. The default for scatter charts is false .

spanGaps

true or false

A null value or NaN (not zero) causes a break in the line if this property is false. The default is false.

Configuration properties for line charts

Global options for line elements are configured using the Chart.defaults.line object. To hide all lines as default, use the following code:

Chart.defaults.line.showLines = false;

Locally, they are defined directly inside the options object. You can override the default in a chart with the following code:

options: { showLines: true }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset