Altering the appearance of the xy axis on a line chart in Chart.js version 4 by either removing it entirely or adjusting its color

I am facing an issue with my chart.js code where I am trying to remove both the axis lines from the graph but still display the grids (NOTE)

` const MAINCHARTCANVAS = document.querySelector(".main-chart")

new Chart(MAINCHARTCANVAS, { type: 'line', data: { labels: ["Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" , "Sun"], datasets: [{ label: 'My First Dataset', data: [7,5,7,7,8,7,4], borderColor: "#4F3422", tension: 0.4, borderWidth:7, borderSkipped: true, }] }, options: { scales: {

        x:{
            grid:{
                display:false,  
            },
            border:{
                didplay: false,
            }
        },

        y:{
            drawBorder: false, 
            beginAtZero: true,
            grid:{
                lineWidth:3,
                color:"#E8ddd9",
            },
            border: {
                display:false,
                dash: [10,16],
            },
            ticks: {display: false}
        }
    },

    plugins: {
        legend: false, // Hide legend
        tooltip:{
            enabled: false
        },
        backgroundCircle: false
    },
    responsive: true,
    maintainAspectRatio: false,
    elements: {
        point:{
            radius: 3
        }
    }
}

}) `

this my previous code I had tried

changing color or removing the axis enough for me

sample img for the reference

i am expecting like this

expected output

Try to change the color of it to transparent or try to remove it

Answer №1

It appears from your query that you are looking to remove the baseline on both axes.

To achieve this, simply include the following code in your options:

scales: {
      x: {
          display: false, // hiding the entire data of the x-axis
         },
      y: {
          display: false,
          }
 }

If you wish to customize grid lines, ticks, and the dash "-", which appears between ticks and the base border of the axis, you can use the following code:

grid: {
    color: 'rgba(100, 250, 132, 0.4)', // specifying grid lines color
    drawTicks: false, // removing the "-" marker between tick and base border
    drawOnChartArea: true, // borders within the chart area
},
ticks: {
    color: 'red', // defining tick color (set to "transparent" if you want to hide ticks)
    display: true, // set to false to hide tick labels (e.g., red, blue, etc.)
}

Hope this solution works for you. Thank you!

var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
  type: 'line',
  data: {
      labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
      datasets: [{
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
          backgroundColor: 'rgba(255, 99, 132, 0.2)',
          borderColor: 'rgba(255, 99, 132, 1)',
          borderWidth: 1
      }]
  },
  options: {
      scales: {
          x: {
              display: false, // hiding the entire data of an axis
          },
          y: {
              display: false,
          }
      }
  }
});
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id="myChart"></canvas>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm currently in the process of incorporating horizontal scrolling into various sections of an image gallery. The images will stack vertically only when the window width

I am currently developing an image gallery with multiple sections that contain various images. My goal is to arrange each section of images in a single row, allowing horizontal scrolling similar to Netflix's layout. However, I'm facing challenges ...

Using AJAX for redirection following a successful PHP post without any errors

I am fairly new to javascript, but I have successfully posted form data to a php file. However, I am now encountering an issue with validations on the php file. What I need is for this ajax request to display the error message if any validation fails and t ...

Increase value of field in subdocument of Mongoose if it already exists, otherwise create a new subdocument

My Goal and Query In my project, I have a data structure called userSchema, which includes an array of operationCountSchema objects. My objective is to write a static method that can update the count field in one of these operation count subdocuments base ...

Sorting items using jQuery filter

I am working with two sortable div containers that are connected using connectWith. Both containers contain draggable items that can be moved as desired. These items have specific classes such as group1 and group2. Let's refer to the containers as con ...

What is the process for incorporating an additional input in HTML as you write?

I am looking to create a form with 4 input boxes similar to the layout below: <input type="text" name="txtName" value="Text 1" id="txt" /> <input type="text" name="txtName2" value="Text 2" id="txt" /> <input type="text" name="txtName3" valu ...

How to extract text from a <div> element using Selenium

Can someone help me with a Selenium question in Python? I need to extract the text "D. New Jersey" from a webpage. The location of this text may vary on different pages, but it is always under "COURT:". The HTML snippet looks like this: <div class=" ...

What's the best way to determine the background image on this website? I'm in the process of replicating a site on

I have been asked to clone the website in order to create a Wordpress site. The original site is currently on Kajabi platform. I managed to download all images from the Kajabi site by right-clicking and selecting download. However, there are certain image ...

The CSS modifications are only visible in my browser after I delete the browsing data

After setting up a landing page with simple text in the center of the screen using flex, I encountered an issue. Whenever I made changes to the CSS, they would not reflect in my browser unless I cleared the browsing data (history, cookies, etc). This probl ...

When attempting to utilize nsIPrefBranch in a Firefox extension to save data, an unexpected error of NS_ERROR_UNEXPECTED occurs

I am facing a challenge with saving persistent data in a Firefox extension. Currently, I am attempting to utilize nsIPrefBranch in the following manner: var db = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.ns ...

PubNub's integration of WebRTC technology allows for seamless video streaming capabilities

I've been exploring the WebRTC sdk by PubNub and so far, everything has been smooth sailing. However, I'm facing a challenge when it comes to displaying video from a client on my screen. Following their documentation and tutorials, I have writte ...

How to update data in AngularJS grid component using ng-bind directive

As a newcomer to AngularJS, I'm facing an issue that I need help with. Here's my problem: I have an ng-grid connected to a table. Inside the grid, there are values along with an ID (which is a foreign key from another table). Instead of display ...

`Multiple Autocomplete feature that allows rendering of previously selected items`

I've encountered a slight issue with my autocomplete feature. On the same page, I have two different autocompletes set up. Both of them pull elements via ajax from separate sources and use the _render option to display the items. The problem arises wi ...

The ideal way to markup a calendar: including a list of times, day containers, and events

Currently, I am creating markup for a one-day calendar display. The calendar consists of a list of times on the left side, ranging from 9am to 9pm, and the events for the day on the right side. I have used a <table> for the list of times, a <secti ...

Arrange the data in the table to ensure that it is organized neatly into the appropriate columns

I am currently working on a project that involves creating a table to display user answers for purchased tickets under the corresponding questions. If a question has not been answered, I want to show a dash symbol instead. However, I am encountering an is ...

The error message indicates a validation issue with the img tag: The attribute src has an invalid value, as it uses a backslash () as a path segment delimiter instead of

<div class="logo"> <img src="assets\images\main-logo\logo.jpg" alt="logo"> </div> </a> </div> The code was validated using validate.w3.org and this error was encountered: Bad value asse ...

Total number of requests made since the previous reset

I'm currently working on developing an API and I need to set up a route like api/v1/status in order to check the server status. This route should return a JSON response with the total number of requests made to the API since it became active. However, ...

An observer is handed to me when I receive an array as a parameter

How can I use an array as a parameter instead of just receiving an observer? When trying to utilize the array, all I get is an observer. The data appears correctly when using console.log in the function that fetches information from the DB. Despite attem ...

Every fourth list item, beginning with a designated number

I'm attempting to add a border to specific list items in my HTML. I want the border to start from the 9th child and then continue every 4th child after that. For clarification, I'd like the 9th, 13th, 17th, 21st, 25th... list items to have white ...

Get started with the free plan for sails.js on Paas

Looking to test out my sails.js application deployment options. Can't seem to find sails.js on the supported list for Heroku and OpenShift's node.js offerings. Are there any free Platform as a Service (PaaS) plans available for sails.js? ...

Guide on resolving issues with Chart.js doughnut chart not displaying background colors or labels properly while utilizing props

I have implemented Chart.js to display a doughnut chart, aiming to utilize props for dynamic data rendering through API calls. However, I am facing an issue where the sections of the chart are displaying without any background color. Can someone assist me ...