Recently I am using the Chartjs library for creating graphs on my website and in that we need to set the title of the y-axis and graph, and I notice that some people also facing the same issue as there is no information about it in the documentation. So I decided to write this article for helping other developers.
How to set ChartJS set Chart Title, Name of X axis and Y axis
Heytoday’s article is about charts and I’m talking about charts. Javascript library a very powerful library to create, to easily create different kind of charts. Using below option you can easily set Chart Title, Name of X axis and Y axis.
options: {
plugins: {
title: {
display: true,
text: 'Visitor',//setting chart title
}
},
scales: {
x: {
display: true,
title: {
display: true,
text: 'Year'//setting Name of X axis
}
},
y: {
display: true,
title: {
display: true,
text: 'Visitor'//Name of Y axis
}
}
}
}
How to add axis titles in chart.js charts
<!DOCTYPE html>
<html>
<head>
<title>Chart.js-Multi line charts </title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.7.1/dist/chart.min.js"></script>
</head>
<body>
<div style="margin-left:5%;margin-right:5%">
<canvas id="myLineChart" style="width:100%;max-width:80%"></canvas>
</div>
<script>
var xValues = ["Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Aug", "Oct"];
const MultiLinechartData = {
type: "line",
data: {
labels: xValues,
datasets: [
{
label: 'Visitor',
lineTension: 1,//this property is used for setting the line curved
borderColor: 'red',
data: [300, 450, 450, 550, 700, 620, 1200, 1120, 1050, 1159, 1120]
}
]
},
options: {
plugins: {
title: {
display: true,
text: 'Visitor',
}
},
scales: {
x: {
display: true,
title: {
display: true,
text: 'Year'
}
},
y: {
display: true,
title: {
display: true,
text: 'Visitor'
}
}
}
}
};
new Chart("myLineChart", MultiLinechartData);
</script>
</body>
</html>
*Thank you so much if you have a question please comment
And then we can specify the new variable data one, where we can just specify the values of our answers to the question. So do you like Donuts? Yes, but in green and 69% said yes, and 31% said yes. Button-green. And then we can specify our
Let colors one equals two. And now lets for both answers, give a certain color. For the first one, let’s give 49 a nine EA. And for the second one, let’s hand over 36 cabs.
Basically, we could have put those stuff directly in here. So we could have put the labels directly here, the data directly here, and the background colors right here in the specification of the chart. But I like to separate it because I think it’s easier to change afterward. Let’s have a look at our index. Html file.
Here we are. Let’s refresh it. And you can see nothing because we got a syntax error in line 19. Let’s have a look. Line 19 displays truer.
I forgot a comma here. My bad. Let’s save it again, go back, refresh it, and here you can see our chart. So do you like Donuts? Yes, but in green.
And that’s it. Isn’t it easy? Right. All right, so our next chart will be a bar chart and we want to answer the question which airline carries? How many passengers?
So let’s Google a little bit passengers by airline and let’s check out Wikipedia here world’s largest Airlines passengers carrier and let’s have a look at 2022 and display what we see here. So those values are in a bar chart.
The post [Simple Trick]-In Chart.js set Chart Title, Name of X axis and Y axis appeared first on Software Development | Programming Tutorials.
Read More Articles
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- jQuery Ajax GET Example with Parameters
- How to Pass Parameters in AJAX POST?| JQuery Ajax Post Json Example
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- How to add, edit and delete rows of an HTML table with Jquery?
- Registration form with image upload in MVC using jquery Ajax
- How to make an Inline editable table in MVC using jquery?
- Insert Update Delete Using Jquery Ajax and Modal Popup in Mvc
- [Solved]-How to Upload pdf file using jquery MVC?
- Dynamically creating graphs with jQuery
- jQuery Form Plugin - HTML inside JSON respone
- Jquery style div and add title according to div tag
- Exclude a tr from parents('tr')
- Auto Select Dynamic Dropdown Matching value of php variable
- jQuery If dropdown is selected
- Change checkbox and label for ID
- PHP Image Upload Via JQUERY
- Script or software: Take a section of HTML from a page and use it in another page
- can jquery $.getJSON's JSON data be assignable to other variable?
- radio group + javascript
- How to know margin-left auto pixels from the left side?
- How to solved small validation problem (It is practically finished, except for a small detail ..)
- Asp.net Core JQuery scroll to div on page load not working
- Click on absolute positioned image does not bubble up to underlying image
- How to expire session if a have a setinterval js running?
- add something to Jquery selection and format
- Ajax getting 400 Bad Request when submitting Form only on Firefox
- Checkbox list in columns via JQuery
- favorite and unfavorite button problem laravel
- jQuery random image fader
- Emailing a piece of Dom
- Cross-domain AJAX request to the WCF
- How to save a part of an image using its coordinates in JavaScript
- jquery val returns jquery function
- JQuery->event Continue
- How to click a web element at its center via JS?
- Load WordPress 5.2 jQuery Script From CDN
- Jquery compare 2 type of array by id and remove an object where the id is not equal
- Is Annotation in Javascript? If not, how to switch between debug/productive modes in declarative way?
- How to create popup using jquery
- Get selected item value using a server side add button in datatables jquery library
- Escaping html in Jquery
- Jquery search more than one variable - bigcommerce store checkout
- Smooth div scroll: Last picture falls to the bottom line
- How i can create alert when time runs out in this code
- Get a table cell value where I have a checkbox checked
- PHP AJAX data not returned to HTML file
- Argument of type '() => JQuery' is not assignable to parameter of type '() => boolean'
- Remember the last selected tab with localstorage
- How to create an Ajax Cascading/Chained/Dependant Dropdown list or Select Box?
- Laravel 8 Quilljs save data to database
- Cascading jQuery Image Fallback
- JSON object should appear in div when click on submit
- Animate effect when div detected through viewport
- Close Ajax:PopupControlExtender on escape key press
- change font-size of jQtransform dropdowns
- Jquery form submit with PHP
- Hang on Page Load: Too much Javascript?
- Unable to attach div after detaching
- return data set has / after every html character
- jQuery use ImageMapper to substitute images
- Jquery multiple checkbox
- How to change default dropdown from php to jquery?
- How to add search result to textbox when clicked in (like Multi-select boxes (pillbox))
- ListBox switch items asp.net jquery
- Validating two linked fields with jQuery Validator
- what is wrong with this jquery delegate code?
- How to select element with specific class in a container
- formatting JSON from URL into HTML
- Jquery add Click event difficulties
- Events update via AJAX and JSON when move into days or months or weeks
- Jquery Shopping with jquery ajax cart working only on 1 product(row)
- Why is my function to hide image not working properly?
- google.maps.event.addListener and fall calls
- Scroll to the top of the div after clicking the correspondent category link
- Delete data from json
- Trying to make a rotate animation
- Response/Request between Javascript/Java Servlet
- Adding element to node
- Using a callback function instead of onchange
- jquery duplicate items when append values to multi select
- Highlight Selected text with different color for each tag
- jquery form submit 400 error
- jqgrid generating xml only for selected row
- sending post request and displaying data in jqgrid
- Javascript image load from localStorage
- How to disable button until input field has a value using AngularJS
- Node.js crawler: find a href by text via cheerio
- How to toggle OFF the ON, while turning ON the NEW w/o display:none
- CORS issues in MVC application 4.5 using ajax request for googleOauth
- Image editing on webpage with javascript
- How to make multiple selection steps to show a link based on selected options?
- Jquery call function on hover if element is of class A but not class B
- Jquery Fancybox
- jQuery image rotate on hover
- Dynamic line between concentric circles in CSS
- Get value of first <td> element in same row as input button
- on checkbox click some php code to be executed in the same page
- Put array of data return from Json Result Inside DataTable Using Ajax Jquery
- How make input not rebind the page?
- Website does not recognise form input modified with javascript
- Implemetation of tabs in Django templates or Jquery
- ASP.NET MVC 3 Ajax.BeginForm Issue using jQuery Submit on Chrome
- remove node in a tree does not maintain its level
- jQuery - IE8 select option will not break/wrap text in a dropdown
- Are there any other reason which can cause 403 error except absence of csrf token in ajax request + django?
- Received values wont enter into the graph
- jquery ui draggable convert tr into div
- is there a way to run javaScript in th:action method thymeleaf
- Sourceforge menu's, cant' seem to find the jQuery function that generates them?
- How to tell jQuery to animate an element that is right on top of the link that triggers it?
- Scroll to next class
- Context menu appears even before clicking
- Dropdown validation in JQuery
- Carousel not working if the code is added dynamically by jQuery
- button only works occasionally using AJAX
- input.change() on javascript value insert
- checking jquery slideup status?
- After button is clicked , another button won't click
- Trying to load images after scrolling to that area
- jQuery UI Selectable Not Working With .dialog open html
- AlertJS modal title doesn't show
- Show a confirmation dialogue for a specific amount of time?
- Spring MVC - Thymeleaf - Map Controller just to replace html div
- knockout.js afterRender does not work in a jquery pop-up
- Error when trying to disable a button in ckeditor
- Can't get the jQuery .getScript to work for calling a function?
- Is there a way to reset a select to the option that was selected on load using jquery
- Remember what key in loop in AJAX callback
- jQuery - String Manipulation
- jquery ui dialog pulls wrong id in dynamically generated list in asp.net mvc
- Get character position of element in HTML
- Why is windows resize not working with a modal?
- How to get Multiple values using Ajax Jquery
- How to pass the "#" character as a parameter from URL using AJAX in MVC
- Jquery "Open url after function completet"
- How to make ajax request only if username is free,
- How to use php validation in ajax request in wordpress?
- How to make text to wrap image in editor
- Html attribute 'Max' with float value make problems
- How to not hide my form element after submission if its css display style was set to none previously
- JQuery Toggle button to turn function on or remove it
- jQuery Geocode to get Postal Address
- Jquery right click, no contextmenu, live and all browser
- Jspdf.js is dropping first space in text in Label from doc.html
- run Javascript locally rather than connecting to JQuery
- Droppable issue when I use axis property in draggable
- How to pass multiple variables between jQuery and PHP files using JSON?
- How to add an onclick event to an infowindow in Google Maps?
- how to use relationship ajax with laravel 5.8?
- Jquery display loader in different divs
- Push content off page
- jquery expand / collapsible list not working
- How append a json data in select box with optgroup
- How to validate if the data is entered in the text field when the checkkbox is checked
- Link 'Out' of jQ
- jQuery rebinding .click?
- jQuery .live() "click" event being unbound when new matches are added to the DOM
- Jquery Caching issue?
- Toggle the Background Color between two links to show which is active using jquery and css?