score:0
in case you want to produce a horizontal bar chart, you could define the x-axes as follows:
scales: {
x: {
min: 0
},
x1: {
position: 'top',
min: 0,
max: 9
}
}
please take a look at the runnable sample below and see how it works when the data is dynamic:
var data = [3, 6, 8, 9, 31];
new chart('mychart', {
type: 'bar',
data: {
labels: ['a', 'b', 'c', 'd', 'e'],
datasets: [{
data: data,
bordercolor: '#00d',
}]
},
options: {
indexaxis: 'y',
plugins: {
legend: {
display: false
}
},
scales: {
x: {
min: 0,
max: math.max(...data)
},
x1: {
position: 'top',
min: 0,
max: math.max(...data)
}
}
}
});
canvas {
max-height: 180px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.5.1/chart.min.js"></script>
<canvas id="mychart"></canvas>
score:1
in case you want the see the same ticks
at the top of the chart, simply define a second x-axis as follows:
x1: {
position: 'top'
}
please take a look at below runnable code and see how it works:
new chart('mychart', {
type: 'line',
data: {
labels: ['a', 'b', 'c', 'd', 'e', 'f'],
datasets: [{
data: [1, 3, 6, 2, 8, 9],
bordercolor: '#00d',
}]
},
options: {
scales: {
x: {
},
x1: {
position: 'top'
}
}
}
});
canvas {
max-height: 180px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.5.1/chart.min.js"></script>
<canvas id="mychart"></canvas>
Source: stackoverflow.com
Related Query
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- 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
- Minimum value for x Axis doesn't work for horizontal bar chart | ChartJS
- ChartJS: how to make a bar chart with a horizontal guideline:
- How do I create a stacked horizontal bar chart with Chart.js in React?
- ChartJS horizontal bar with numbers on both scales
- 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
- Rotating a chart.js pie chart with two datapoints to align both sectors on horizontal axis
- How to order a horizontal bar chart - chartJS & Chart.HorizontalBar.js
- Draw stacked horizontal bar chart with Average line using ChartJS
- How to make labels on both side from horizontal bar chart js
- CharJS : Is it possible to display stacked bar chart with positive scale on both sides of 0 index
- How to make chart which has both positive and negative value, starts with 0 - x axis
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Horizontal stacked bar chart with chart.js
- chartjs : how to set custom scale in bar chart
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to display inline values in a stacked bar chart with Chart.js?
- ChartJS bar chart with legend which corresponds to each bar
- Chartjs - data format for bar chart with multi-level x-axes
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Horizontal bar with multiple sections in ChartJs
- Stacked horizontal bar chart along total count with chart.js
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- How to change Chart.js horizontal bar chart Width?
- How to remove bars for those bars with zero value in Chartjs bar chart?
More Query from same tag
- Line Chart with null values: How to keep Lines connected?
- How to adjust Chart.js height according to datasets size. Ionic 3
- angular-chart error on line chart: unable to parse color
- How to inject “Chart.js” to my module?
- Chart.js add tooltip at intersection of axes (break even)
- Change pointer line style
- Update the Chartjs push data with ajax
- Can I color the first bar in "Bart Char" differently?
- Can't resolve 'chart.js/auto'
- Bars on second X Axis not showing
- Charts js showing only when positives data
- Chart js scatter graph labels
- Chart js with problems when using too many series
- PrimeNg Pie Chart - By default show all tooltip?
- Chart.js adds unwanted padding on top and below chart with padding set to 0
- Load JSON to display data, using ng-repeat {ANGULAR.JS}
- How to add background image in bar chart column in Chart.js?
- Using Chart.js, how do I avoid having tooltips overlap?
- How to make bootstrap 4 column height the same as row height
- Chartjs sample line chart setup doesn't show dataLabels
- Why won't this html page run, Devexpress documentation ChartJS
- Chart.js pie chart to display "No Data" if the datasets are empty
- Chart.js only displays font changes upon hover
- How to get 2 doughnut charts in one chart (chartjs)
- Adding responsive text inside chart in Charts Js
- ChartJS bar chart with legend which corresponds to each bar
- Why the bar are not aligned the y axis
- Need help in figuring out config for a custom tooltip (chartjs)
- Charts Area JS v2: How to set units?
- Ability to rotate y axis title in chart.js