score:3
Not sure which version of chartjs you are using but if someone comes across this you can turn off the display of 1 or more Axis by using display: false for example the following turns off the display of the x axis.
options: {
scales: {
xAxes: [{
display: false
}]
}
}
score:0
Answer of @Rich Dominelli is correct for chart.js
v2.xx
Here code for chart.js v3.xx to eliminate axis:
(not backwards compatible with v2.xx)
For those interested, following modified code to work with chart.js
v3.xx
option: {
scales: {
x: { // <-- object '{' now, instead of array '[{' before
display: false
},
y: { // <-- object '{' now, instead of array '[{' before
display: false
}
}
};
Following full code example for line-chart without axes in snippet below that you can run:
const labels=["2021-08-02","2021-08-03","2021-08-04","2021-08-05","2021-08-06"];
const data_1=[39,41,42,43,43];
const data_2=[37,38,40,41,39];
const ctx=document.querySelector('canvas').getContext('2d');
const data = {
labels: labels,
datasets: [{
label: 'Data 1',
borderColor: 'grey',
data: data_1
}, {
label: 'Data 2',
borderColor: 'grey',
data: data_2
}]
};
const option = {
scales: {
x: {
display: false
},
y: {
display: false
}
}
};
const chart = new Chart(ctx, {
type: 'line',
data: data,
options: option
});
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- gets you the latest version of Chart.js, now at v3.5.0 -->
<canvas width="640" height="480"></canvas>
score:2
Here's a rough solution:
I found this around line 1600 of Chart.js:
// This is X axis, so draw it
if (index === 0 && !drawHorizontalLine){
drawHorizontalLine = true;
}
I modified it to always be false when index === 0
, which I assume means that we're on an axis:
// This is X axis, so <don't> draw it
if (index === 0 && drawHorizontalLine){
drawHorizontalLine = false;
}
I did something very similar for the Y-axis further down, and then I commented out the code that draws the tiny 5-pixel dashes along each axis as well. If someone knows of a configuration option for this, please share.
Also, I guess I could have just set the line stroke / fill color to the same as the background color...
Source: stackoverflow.com
Related Query
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- Remove excess lines on y axis using chartjs
- Remove y and x axis lines and change axis font style in Chartjs
- ChartJS Line Charts - remove color underneath lines
- How to set ChartJS Y axis title?
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- ChartJS – is there any way to remove blank space around pie charts?
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- How to remove the line/rule of an axis in Chart.js?
- show label in tooltip but not in x axis for chartjs line chart
- how to change background in chartjs and remove background lines?
- Chartjs change the specific label color in x axis in callback function
- Chartjs 2: Multi level/hierarchical category axis in chartjs
- How to remove gridlines and grid labels in Chartjs Radar?
- Chartjs 2.7.3: Set Y data at the correct X position axis
- How do I fix over limit y axis value in ChartJS
- chartjs - Drawing vertical line on integer x axis value
- Map event position to y axis value in chartjs line chart
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- How to remove the Chart.js x Axis bottom line?
- Changing the Y axis unit in Chartjs
- ChartJS - remove axis?
- Chartjs real time graph x axis movement
- Chartjs x axis scaling
- Chartjs change horizontal axis value
- ChartJS / MomentJS - Unable to remove deprecation warning. Graph not showing in firefox/opera
- Chart.js remove border from x/y Axis
- How to add ChartJS code in Html2Pdf to view image
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- Remove gap when updating ChartJS
More Query from same tag
- Chart.js - Tooltips overlapped by bar values
- Multi colored line chart angular and primeng
- Passing Json using JsonResult not working properly
- Chart.js Bar Chart - how to chart bars from 0
- Chartjs bar chart appears empty when page loads
- How to use forEach loop on my array to plot x and y variables on my chart (Chart.js)
- How to change the color of Chart.js points depending on the label
- Hiding legend in PrimeNG
- How To Match Left and Right Tick Intervals with Chartjs
- How to put back the data with a switch?
- Chart.js adds unwanted padding on top and below chart with padding set to 0
- Chart.js not displaying Django Rest API data
- Hide label on slice of Doghnut/Pie Chart Angular ng2-charts
- Chartjs does not show on pdf in yii2 despite showing in html view
- Use Chartjs with reactjs
- Merge Jquery Knob Functionality in Chart Js
- Chart.js get array of currently visible points on graph
- Vuejs - Chartjs doesn't render my own options with api request
- Chartjs - How to get last 7 days on x-axis labels?
- ChartJS and Radar Chart animation
- How to visualize data with chart.js properly?
- React-Chart.js legend onClick function
- Chart.js multiple columns of data for the same label
- How to hide the legend display for a specific chart?
- Why is the child component updating but not re-render Reactjs
- Display Charts based on year select in django
- Chart.js: Display Custom Tooltips, always visible on stacked bar-chart
- JavaScript - Convert dates and times (Chart.js and Moment.js)
- ng2 charts on Angular 9 not responsive
- Adding a for loop/foreach loop for Charts.js