score:22
Accepted answer
Looking at the docs, I can see that multiline labels are possible.
Updated link to documentation: https://www.chartjs.org/docs/latest/general/data-structures.html
I looked at the source code of an example and for multiline labels, they have each multiline in an array where each element of the array is rendered in its own line.
For example:
labels: [['(A)', 'Waking'], '(B)', '(C)', '(D)'],
See DEMO below:
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
window.chartColors = {
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',
yellow: 'rgb(255, 205, 86)',
green: 'rgb(75, 192, 192)',
blue: 'rgb(54, 162, 235)',
purple: 'rgb(153, 102, 255)',
grey: 'rgb(201, 203, 207)'
};
var config = {
type: 'line',
data: {
labels: [
['(A)', 'Walking'], '(B)', '(C)', '(D)'],
datasets: [{
label: 'My First dataset',
fill: false,
backgroundColor: window.chartColors.red,
borderColor: window.chartColors.red,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
]
}, {
label: 'My Second dataset',
fill: false,
backgroundColor: window.chartColors.blue,
borderColor: window.chartColors.blue,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Chart with Multiline Labels'
},
}
};
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d');
window.myLine = new Chart(ctx, config);
};
<script src="https://www.chartjs.org/dist/2.8.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.cloudflare.com/cdn-cgi/scripts/a2bd7673/cloudflare-static/rocket-loader.min.js" data-cf-settings="100752039a7e60f6a2c8f47d-|49"></script>
<div style="width:90%;">
<canvas id="canvas"></canvas>
</div>
Source: stackoverflow.com
Related Query
- How do I place a new line in a label with Chart.js?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How to display Line Chart dataset point labels with Chart.js?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to add area with break on line chart with fill color
- How do I use my chart.js line chart with handlebars?
- How to change the label and grid line position on a timeseries chart in Chart.js 3?
- How to create Bar chart that gets updated from new ajax requests with ChartJS?
- how to label axis within radar chart with chart.js
- How to reduce the number of points shown on line chartjs chart with a large dataset?
- How to introduce newline character in xAxes Label with chart js
- How do you make a progressive line chart with time as the X axis?
- How to add new dataset in line chart of chart.js by iterating over dictionary in JavaScript?
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- How to get line x value from Label chart js
- How to use chart.js to plot line chart with x axis as time stamp in seconds
- How to load new chart (chartsjs) from api call with jquery?
- How to dynamically update data of line chart used with chart Js?
- How to update chart.js chart with new data?
- How to plot line chart with multiple datas, but only 2 labels?
- How can I add new data points to an existing chart with chart.js?
- chart.js - how to draw and manage line when only one label present in chart js Linechart
- How to open a new Tab with javascript and display some chart
- How to configure chart.js line chart with very low minimum height, and only 0 and 1 (no decimals) as ticks on the y-axis
- How to change line chart data label to icon or image in chart.js
- Chartjs line chart gets all scrambled up when an x value coincides with a label
- Line Chart with null values: How to keep Lines connected?
More Query from same tag
- angular chart.js not resizing (shinking) in a flexbox
- Create charts with a loop in Django with charts.js
- Chart.js and right side free space
- Style individual points from one dataset in Chart.js
- Stacked bar chart results in misaligned bars
- Create chart in SPA(Aurelia) with MVVM pattern
- How to make react-chartjs-2 responsive on mobile?
- How to Modify ToolTips in Yii2 using dosamigos\chartjs\ChartJs?
- ChartJS Tooltip - Change Data Format Displayed
- y=0 gridline (or axis?) not showing in chart.js
- Height for chart area (not the canvas size)?
- Is there a way to highlight a line on a line graph with hover?
- Chart.js Show label/tooltip for single point when multiple points coincide
- Dynamically update values of a chartjs2.0 chart
- Puppeteer with Chart.js
- Change tooltips title at chart.js?
- How to export chart.js graph to svg in vue?
- Using data from API with Chart JS
- Chart.js PolarArea not able to chance arc width and color
- Chart.js: changing tooltip template
- Chart in Ionic Framework doesn't show up
- Importing JSON to data and labels for chart.js
- Chart.js javascript from db stopped working after adding axes
- How to append text or symbol to tooltip of chart.js
- Chart.JS: How to make sharp lines to smooth curved lines
- How to display that data was unavaible during some time in a Chart.js (or any other library's) timeline graph
- Customize fill colors for ChartJS 3.x using beforRender plugin event
- Chart.JS removing data stuck in loop
- Is it possible to have tick stepSize for each dataset in Chart.js?
- Extend chart.js horizontal bar graph to include a vertical line