score:0
The lines can be drawn using floating bars tied to the separate axis y2
. To do so, you need to add another dataset
as follows (I don't exactly understand what values you want to display, hence I randomly chose 40
, 65
and 55
):
{
label: "Lines",
backgroundColor: "rgb(255, 0, 0)",
data: [40, 65, 55].map(v => [v - 0.3, v + 0.3]),
yAxisID: 'y2',
order: -1
}
Further you must define a new scales
option
as shown below:
y2: {
display: false
}
Please take a look at your amended runnable code and see how it works.
var data = {
labels: ["January", "February", "March"],
datasets: [{
label: "Dogs",
backgroundColor: "rgba(237, 192, 169)",
data: [20, 10, 25]
},
{
label: "Cats",
backgroundColor: "rgba(253, 234, 175)",
data: [70, 85, 65]
},
{
label: "Birds",
backgroundColor: "rgba(179, 211, 200)",
data: [10, 5, 10]
},
{
label: "Lines",
backgroundColor: "rgb(255, 0, 0)",
data: [40, 65, 55].map(v => [v - 0.3, v + 0.3]),
yAxisID: 'y2',
order: -1
}
]
};
new Chart('myChart', {
type: 'bar',
data: data,
options: {
indexAxis: 'y',
plugins: {
legend: {
display: false
}
},
scales: {
y: {
stacked: true,
grid: {
display: false
}
},
y2: {
display: false
},
x: {
stacked: true,
beginAtZero: true,
grid: {
display: false
}
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.min.js"></script>
<canvas id="myChart" height="100"></canvas>
Source: stackoverflow.com
Related Query
- Draw stacked horizontal bar chart with Average line using ChartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- How to draw Horizontal line on Bar Chart Chartjs
- Can't Draw Horizontal Line on Graph Using ChartJS Annotation Plugin and Primevue Chart
- How to draw multiple color bars in a bar chart along a Horizontal Line using chart.js
- Chart.js Draw a Stacked Bar Chart with Limit Line
- Horizontal stacked bar chart with chart.js
- Display line chart with connected dots using chartJS
- Stacked horizontal bar chart along total count with chart.js
- Multiple stacked bar chart using ChartJs
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- Stacked bar chart with rounded corner of bar using Chart.js
- Adding line over stacked line chart with ChartJS
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- Chart.js - Horizontal line on Bar chart interferes with tooltip
- Stacked Floating Horizontal Bar using ChartJS
- Chart.js - draw horizontal line in Bar Chart (type bar)
- How do I create a stacked horizontal bar chart with Chart.js in React?
- ChartJS 2.9.4 can't overlay line data on Horizontal Bar chart
- Stacked bar chart with chartjs with included values
- Real-time line chart with ChartJS using Ajax data
- ChartJS - Horizontal Stacked Bar Chart Tooltip being cut off by Bottom of Canvas
- ChartJs - stacked bar chart with groups - how to create second x-axis with stack id
- ChartJS - would like to create a mixed chart with horizontal Bar and a dot to represent the answer from the current user
- Drawing a horizontal line on a stacked bar chart on hover (chart js)
- ChartJS 2.7.3 stacked bar chart with overlap
- Chartjs v3 overlap stacked bar chart with groups
- Stacked Bar Chart With Line Chart In Charts.js
- ChartJS: Is this horizontal stacked bar and line graph multiaxis chart even possible?
More Query from same tag
- how to hide tick labels on chartjs/vue-chartjs
- Angular Charts - not able to read data
- Chart JS - Horizontal Bar Chart Not Filling Canvas
- Make months on x-axis clickable on chart.js line chart
- How to generate chartjs charts to pdf using laravel?
- Chart.js stepSize not working with min
- Limit chart.js X axis ticks
- Key Management: Hardcoded Encryption Key for chart.js
- Chart options in angularJs (NodeRed Charts)
- Line chart with combination of fill and line
- How to include many datapoints to plot in chart.js
- How can I change the cursor on pie chart segment hover in ChartJS 3?
- drawing bar chart with chart.js jQuery
- Charts.js candlestick (Financial Charts) displays half the bar in the beginning and the end
- How to add several labels to the same set of data in chartjs?
- Does this library have a way of showing a world map?
- Angular charts not working with Angular 5, Showing below error attached screen shot
- chartjs tooltip html: Use data to populate tooltip
- ChartJS display legend
- Call ChartJS details in main Javascript file
- Javascript 2D array getting each element
- PHP string data passed to Chart.js not rendering well
- Chart.js tooltip yAlign
- ChartJs doesn't display the line item legend
- ChartJS set default options only to specific Canvas, not globally
- Meteor with Chart js cannot read property ‘getContext’ of null only AFTER new document in collection?
- Foreground chart by mouse
- Chart.js - How to create a different global configuration between the x axis and the y axis
- Vue watch not noticing changes on component prop
- Update only Chart.js without animations and without refreshing the browser