score:6
Accepted answer
Have a try with
var myChart = new Chart(ctx, {
//chart data and options,
onResize: function(myChart, size) {
var showTicks = (size.height < 140) ? false : true;
myChart.options = {
scales: {
xAxes: [{
ticks: {
display: showTicks
}
}];
}
};
}
});
score:0
For Angular
you can make the logic like this...
the screen.width
will counted as your viewport width
canvas: any;
ctx: any;
legend: any;
font: any;
constructor() { }
ngOnInit(): void {
this.canvas = document.getElementById('tpChart');
this.ctx = this.canvas.getContext('2d');
this.legend = (screen.width < 575) ? false : true; //when viewport will be under 575px
this.font = (screen.width < 1200) ? 14 : 16; //when viewport will be under 1200px
let tpChart = new Chart(this.ctx, {
type: 'doughnut',
data: {
datasets: [{
borderWidth: 2,
data: [70, 50, 40, 30],
backgroundColor: [
'#00CDB6',
'#F08C2E',
'#0F9AF0',
'#F16C51',
],
}],
labels: [
'United Kingdom',
'Bangladesh',
'United States',
'Others',
]
},
options: {
responsive: true,
cutoutPercentage: 65,
spanGaps: false,
legend: {
display: this.legend, //This will work dynamatically
position: "right",
align: "center",
labels: {
fontColor: '#484848',
boxWidth: 10,
fontSize: this.font, //This will work dynamatically
fontFamily: "Cabin",
padding: 25,
usePointStyle: true
},
}
},
});
}
score:9
Try this:
onResize: function(myChart, size) {
myChart.options.scales.xAxes[0].ticks.display = (size.height >= 140);
}
In order to get the option on load on mobile, you should do this:
function isMobileDevice(){
return ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
}
var myChart = new Chart(ctx, {
options :
scales:
{
xAxes: [{
ticks:{
display: !isMobileDevice()
}
}];
}
})
Source: stackoverflow.com
Related Query
- ChartJS hide labels on small screen sizes
- Chartjs hide data point labels
- Hide labels on x-axis ChartJS
- How to hide Chart.js data labels for small screens
- ChartJS on small screen
- Hide all labels and tooltips in Chart.js and make it very small size
- Hide all scale labels in chartjs
- Hide labels from pie chart in chartjs
- How to hide the labels of graphs that are not toggled in ChartJS
- ChartJS have xAxes labels match data source
- How to hide labels by two ticks? chartjs
- Chart.js v2 hide dataset labels
- Hide points in ChartJS LineGraph
- Is it possible in chartjs to hide certain dataset legends?
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Truncating canvas labels in ChartJS while keeping the full label value in the tooltips
- How I can prevent of labels overlapping on mobile screen Chart.js
- Hide Y-axis labels when data is not displayed in Chart.js
- Chartjs radar indexed labels
- Hide gridlines in chartjs without the drawTicks
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- How to remove gridlines and grid labels in Chartjs Radar?
- How to show data values or index labels in ChartJs (Latest Version)
- Chartjs break line for axes tick labels text
- Chartjs Radar - Change color of end point labels
- Chartjs 2.0 - Increase height of x-axis labels
- change long labels to multiline(wrap) label in ChartJs
- Chartjs : data labels getting overlapped in smaller datasets using chartjs-plugin-datalabels
- Show Data labels on Bar in ChartJS
- ChartJS 2.0 - Huddle labels on pie chart
More Query from same tag
- Chart js, pie chart remove borderradius
- Plotting multiple lines (line chart) in Apache Zeppelin using AngularJS
- How to Draw Gantt chart using chart js or other libraries
- Charts on Admin-on-rest
- ChartJS – How to show border on empty pie chart?
- Chart.js how to resend animation command to a chart?
- Center point labels between ticks (Polar Area Chart JS)
- Adding text inside 2 different Doughuts chartjs
- Querying data from Firebase for Chart.js using AngularJS
- How to convert JSON data to object that contains other objects?
- Text inside Doughnut chart using Chart.js and Angular2, Ionic2
- Invalid Date moment.js using Iso yyyy-MM-dd HH:mm:ss
- Angular ChartJs does not show Data for multiple Charts
- Chart.js stacked and grouped horizontalBar chart
- Increase padding between legend and chart with react-chartjs-2
- Chart.js - Add gradient to line chart background
- NG2-Charts Can't bind to 'datasets' since it isn't a known property of 'canvas'
- Chart.js - remove zeros and step numbers in Y axis
- Customizing ChartJS.org
- Chartjs not showing up in Foundation5 Tabs
- Bar chart not starting at 0
- Chart.js drag points on linear chart
- How to use two datasets in chart.js doughnut chart?
- How can I display fixed labels on X-axis while having data on that axis?
- Chart JS grouped sub labels
- Creating a Doughnut chart using JSON and chart.js
- Chart.js LineChart how to show only part of dataset and support horizontal scrolling
- Why scatter chart does not show axes?
- Create a pie chart with chartjs package in R
- Chart js custom datalabel from array