score:4
Accepted answer
Your problem is not related to ticks.stepSize
, this option simply controls how to create the ticks but doesn't change the size of the bars.
You can define the x-axis as a logarithmic cartesian axis as shown in the runnable code snippet below.
new Chart('myChart', {
type: 'horizontalBar',
data: {
labels: ['0-12 hr', '12-24 hr', '1-3 day', '3-15 day'],
datasets: [{
label: '',
data: [20, 0, 0, 34343],
backgroundColor: ["rgba(255, 99, 132, 0.2)", "rgba(255, 159, 64, 0.2)", "rgba(255, 205, 86, 0.2)", "rgba(75, 192, 192, 0.2)"],
borderColor: ["rgb(255, 99, 132)", "rgb(255, 159, 64)", "rgb(255, 205, 86)", "rgb(75, 192, 192)"],
borderWidth: 1
}]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
type: 'logarithmic',
ticks: {
beginAtZero: true,
userCallback: (value, index) => {
const remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));
if (remain == 1 || remain == 2 || remain == 5 || index == 0) {
return value.toLocaleString();
}
return '';
}
},
gridLines: {
display: false
}
}]
}
}
});
canvas {
max-width: 400px;
}
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<canvas id="myChart" height="150"></canvas>
Source: stackoverflow.com
Related Query
- How to make customized stepSize for each horizontal bar in Chart.js graph
- ChartJS: how to make a bar chart with a horizontal guideline:
- How to use set the color for each bar in a bar chart using chartjs?
- How to set X coordinate for each bar with react chart js 2?
- How do I get a different label for each bar in a bar chart in ChartJS?
- How to make labels on both side from horizontal bar chart js
- How to set percentage value by default on each bars in horizontal bar chart js
- how to create bar chart with group and sam color for each group using chart.js?
- How to add second Y-axis for Bar and Line chart in Chart.js?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- Different color for each column in angular-chartjs bar chart
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- how to make a chart.js bar chart scrollable
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- How to set a full length background color for each bar in chartjs bar
- Gradient color for each bar in a bar graph using ChartJS
- How to draw Horizontal line on Bar Chart Chartjs
- PrimeNg bar chart how to show a label for the y-axis
- Chart.js: Minimum value for x-axis at horizontal stacked bar chart
- How to set single color on each bar in angular chart js
- How to make bar chart animation where all bars grow at the same speed?
- How to change Chart.js horizontal bar chart Width?
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- How to show different product name for every bar in chart js
- Minimum value for x Axis doesn't work for horizontal bar chart | ChartJS
- ChartJS horizontal chart display legend on each bar
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- angular-chart.js : how to show numbers in each bar of stacked bar chart
- How to wait for all items to load within ng-repeat before then rendering a chart for each item
- How to draw baseline for bar chart in chart.js
More Query from same tag
- colors are not updated when updating chart
- Chart js animating a line while changing x-axis labels
- ChartJS, Primeng, Gap first and end of line chart
- React Chart.js onClick for custom legends
- Data-labeling ChartJS, Removing Duplicates?
- Moving the zerolines in ChartJS scatter chart
- Chart JS Displays Only Bigger Dataset But Has Both Datasets?
- Automatically update ChartJS with Knockout data-bind
- chart js chart bar chart not showing data from 0
- Add percentage to label badge - doughnut chart.js
- How to use segment property to color line / border color based on value in chart js?
- Change ChartJs axis title dynamically
- Chart.js not showing line chart. What am I doing wrong?
- How to filter chart.js by month
- How to remove trial version watermark in canvasjs using Jquery (without license)
- Chartjs graphs are not respecting height of container
- How to change the position of the tooltip for the Bar type chart in Chart.Js
- Chart.js : Controller for Scatter chart doesn't work for draw function
- Piechart doesn't show up in Canvas
- How to remove the line/rule of an axis in Chart.js?
- How to set Custom tooltip event with Chartjs version 2.X
- Angular4 ng2-charts TypeError: Cannot read property 'length' of undefined
- Can individual bubbles in a chartjs bubble chart have labels?
- Stacked Bar chart fixed width bar chart issue - Chartjs
- How to handle epic long text at y-axis for angular-chart.js?
- Flask Socketio | Update and plot a chart using background tasks created by Flask Executor or ThreadPoolExecutor
- Additional line in BarChart (Charts.js)
- Chart js assign default value for y axis
- Chartjs : Remove specific labels
- How can i do this chart in react?