score:24
Accepted answer
Yes! It is possible.
FIRST
set the usePointStyle
property to true
for legend's labels, in your chart options, like so :
options: {
legend: {
labels: {
usePointStyle: true
}
},
...
SECOND
set pointStyle
property (as per your requirement) for each of your dataset, as such :
datasets: [{
...
pointStyle: 'line'
}, {
...
pointStyle: 'rect'
}]
ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ⧩
var data = {
labels: ['Value [mm]', ''],
datasets: [{
label: "Hi-Hi Limit",
type: 'line',
data: [5432, 5432],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(255, 4, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
label: "Hi Limit",
type: 'line',
data: [5130, 5130],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(250, 255, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
label: "Lo Limit",
type: 'line',
data: [905, 905],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(250, 255, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
label: "Lo-Lo Limit",
type: 'line',
data: [604, 604],
backgroundColor: 'rgba(250, 255, 255, 0)',
borderColor: 'rgba(255, 4, 0, 100)',
borderWidth: 3,
radius: 0,
pointStyle: 'line'
}, {
type: 'line',
label: "Level",
data: [4800, 4800],
backgroundColor: 'rgba(0, 119, 220, 1)',
borderColor: 'rgba(0, 119, 220, 1)',
borderWidth: 1,
radius: 0,
pointStyle: 'rect'
}],
};
var options = {
legend: {
position: 'right',
labels: {
usePointStyle: true
}
},
scales: {
yAxes: [{
gridLines: {
display: true,
color: "rgba(255,99,132,0.2)"
}
}],
xAxes: [{
gridLines: {
display: false
}
}]
}
};
Chart.Bar('chart', {
options: options,
data: data
});
body {
background: #1D1F20;
padding: 16px;
}
.chart-container {
position: relative;
margin: auto;
height: 80vh;
width: 80vw;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<div class="chart-container">
<canvas id="chart"></canvas>
</div>
score:0
With recent versions of Chart.js (I'm using 3.5.1), you need to enable this in the options => plugins section of config:
options: {
plugins: {
legend: {
labels: {
usePointStyle: true
}
}
}
}
Source: stackoverflow.com
Related Query
- Change Chartjs Legend Icon Style
- How to change legend icon on hover Chartjs
- How to change the color of legend in chartjs and be able to add one more legend?
- In ChartJS is it possible to change the line style between different points?
- Removing ChartJS 2 border and shadow from point style legend
- Change style of hover and tooltip in chartjs or ng2-charts
- How do I change axis, title, legend formatting on chartjs template
- Change point style in Chartjs via external event
- change legend item style when dataset is hidden
- Change the style of the border in ChartJS
- Can you change legend style for bar datasets with chart.js?
- I can't change the legend position in Laravel Charts & ChartJS
- Change legend style from bar to line chart.js 2.4.0
- how to change point style legend to diamond in chart js
- How can I move chartJs legend left side and change the width and Hight of the chart?
- Unable to change the legend symbol to rounded square in chartjs in React
- VueJS + Chartjs - Chart only renders after code change
- ChartJS - Change legend to toggle buttons
- Remove y and x axis lines and change axis font style in Chartjs
- Try to change style in current month in chartJS
- Chartjs change grid line color
- Custom Legend with ChartJS v2.0
- how to change size of point in ChartJS
- Change legend position of ng-charts (using angular2)
- chartjs datalabels change font and color of text displaying inside pie chart
- Chartjs Bar Chart Legend
- ChartJS display legend
- Chart.js change legend toggle behaviour
- Change point size and color on hover in chartjs
- Change point color on click using ChartJS
More Query from same tag
- Different color for each column in angular-chartjs bar chart
- Getting "TypeError: document.getElementById(...) is null" when using react.js with chart.js
- Chart.js label value
- Using a prepared dataset in chart.js
- ChartJs line chart repaint glitch while hovering over
- Chartjs is stripping trailing zeros in decimal datasets
- Include Percentage In Legend
- ionic display chartjs data from json http request
- how to add multiple data in chart js dynamically from JSON
- How to use a Data Array within a Chart JS dataset?
- Chart.js - Increase spacing between legend and chart
- How to decrease the barthickness in ng2-charts?
- jquery - How to update line chart.js with multiple datasets
- How can I add vertical line and label for each point in Chart.js?
- Loading and updating dynamic charts with dynamic data (chart.js)
- chartkick chart.js change colour of axis and colour of axis title
- Changing the opacity of the colour on the Polar Area chart
- How to resolve npm error needing an appropriate loader?
- problem with multiple datasets in chart.js
- Are you able to offset a secondary y-axis in ChartJS, by a decimal value, whilst keeping the same scale for both y-axes?
- chart js stripline? like one from canvas
- Chart Js function (Chart.js) is stuck in a loop
- return array from ajax
- Chart.js V3 Fill Below 0
- Chart.js error: Bar is not a function
- Chart.js - Bar values showing on the middle of bar
- How to change the color of the bar in barchart if the data is negative - Angular Charts
- How to add data to chart.js with a for loop
- Chart js padding isn't working for data labels
- Chartjs Nested Pie/Doughnut charts