score:3
Accepted answer
finally i got the solution after many trial-and-errors. i have to say that the documentation of chart.js
is quite unclear and should be improved.
my findings are:
xlabels
andylabels
approach is not working. there are no clear documentation on these two parameters.- don't care about setting the
type
tocategory
.chart.js
only accepts numerical values; you have to map the values to strings by using your own callback method.
var options = {
type: "line",
data: {
labels: ['january', 'february', 'march', 'april', 'may', 'june'],
datasets: [{
label: "my first dataset",
data: [1, 2, 3, 1, 1, 1],
fill: false,
bordercolor: "rgb(75, 192, 192)",
linetension: 0.1
}]
},
options: {
scales: {
yaxes: [{
ticks: {
max: 3,
min: 1,
stepsize: 1,
callback: function(label, index, labels) {
switch (label) {
case 1:
return 'a';
case 2:
return 'b';
case 3:
return 'c';
}
}
}
}]
}
}
}
var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
<canvas id="chartjscontainer" width="600" height="400"></canvas>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.4.0/chart.min.js"></script>
Source: stackoverflow.com
Related Query
- How to create a chart that uses strings for both the X and Y axes?
- how can i use chart.js to create a chart that has one time series line and one linear line on it at the same time?
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- How can I have different values for the chart and the tooltip in chart.js?
- How to plot a line chart which has both the start and points outside the canvas area using Chart.js
- How to ensure that a Chart.js line chart uses all space available on the y-axis?
- How do you create rounded corners on the top and bottom of a bar chart and the between 2 part still draw like image?
- How to set the data of chart in angular which is taken from the backend nodejs api that is store in mongodb and showing on the html page
- How to take data from an API and create a chart on that using Chart.js and Angular 8?
- 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?
- chart js tooltip how to control the data that show
- Chart js: how can I align the legend and the title
- PrimeNg bar chart how to show a label for the y-axis
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- How to get the actual chart width and height in chart.js
- How to draw a needle on a custom donut chart and add datapoints to the needle?
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- How to create a gantt chart using Chart.js and populate dates?
- Chart is too big. How can I reduce size for the chart in vue js?
- How to create a variable for chart js datalabel plugin formatter
- 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 use set the color for each bar in a bar chart using chartjs?
- How to set the xAxes min and max values of time cartesian chart in Chart.js
- How to style a pie chart in chart js? I want to change the border color, border width and give them shadow
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How to sort MMMYY on Chart.Js and display the values that match the month?
More Query from same tag
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chart.js legend position error
- Chart.js: different dataset size
- Chart.js - Uncaught ReferenceError: chart is not defined
- chart.js - Horizontal lines per bar
- Chartjs updating point titles
- Chartjs Stacked bar chart not displaying correctly
- error TS2322: Type 'string' is not assignable to type 'keyof ChartTypeRegistry'
- Grouping the object by key for Chartjs bar chart
- Chart.js labels of x-axes makes useless space in chartarea
- change stroke line color in chart according to datasets in react native
- Angular chart showing series but no data
- Chart.js Legend not showing
- Chart.js click event to open a custom tooltip does not work sometimes
- displaying bar chart in laravel
- chartjs chart spilling out of container
- Obtain max value of y axis of line chart rendered with Chart.js
- Angular 12 + Chartjs 3.3.2 TypeError: Cannot read property 'left'
- I can't change the legend position in Laravel Charts & ChartJS
- Ticks callback not displaying strings containing decimal
- Chart.js nuget Package with angularJS
- chart.js data forming though the API dynamically based on selects
- Data not fully displaying on bar chart
- Add chart using chart.js in codeigniter
- Adding image on the top of bar in chartjs
- Chart.js date formatting use for
- Chart Js Stacked Bar Chart with Multiple levels or categories
- How to clear the data for a angular-chart
- laravel-chartjs not displaying anything
- Chart.js - how to disable everything on hover