In this article, we’re going to answer the question of How to leave just points without lines in ChartJS. Basically, we want to remove the connecting lines between dots, because we just want to show the dots in the line chart instead of connecting line.
To hide the line chart and only show the dots, we just need to set the showLine property of chart js to false.As shown in below example.
datasets: [
{
label: 'Sale',
lineTension: 0,
borderColor: 'red',
data: [343, 343, 8, 550, 89, 89, 898, 232, 343, 243, 554],
pointBackgroundColor: 'red',
pointRadius: 6,
showLine: false
}
]
Show just points without lines
<!DOCTYPE html>
<html>
<head>
<title>ChartJS-How to leave just points without lines</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:100%"></canvas>
</div>
<script>
var xValues = [2011, 2012, 2013, 2014, 2016, 2017, 2018, 2019, 2020, 2021, 2022];
const MultiLinechartData = {
type: "line",
data: {
labels: xValues,
datasets: [
{
label: 'Sale',
lineTension: 0,
borderColor: 'red',
data: [343, 343, 8, 550, 89, 89, 898, 232, 343, 243, 554],
pointBackgroundColor: 'red',
pointRadius: 6,
showLine: false //this line very importnent for hiding lines
}
]
},
options: {
plugins: {
title: {
display: true,
text: 'Sale Chart',
}
},
scales: {
x: {
display: true,
title: {
display: true,
text: 'Year'
}
},
y: {
display: true,
title: {
display: true,
text: 'Sale($)'
}
}
}
}
};
new Chart("myLineChart", MultiLinechartData);
</script>
</body>
</html>
*Thank you so much if you have a question please comment
And please note the ID My chart here. Keep this in mind before we now jump into our script JS which we create now basically let me move this a little bit away. Alright, welcome to the JavaScript part here. So first of all let’s create a new variable, let My chart one, and query our Mychartone ID. So document get element by ID like this and let’s query the My chart ID on the canvas element from our HTML.
So when we go back here My chart this ID here we are getting this and we have to set the context here. Forget context because we are creating two-dimensional charts here. Next, a new variable, let chart one which actually creates a renders chart. So for this, we can use a comment new chart. We have to give our variable here where the My chart ID is queried.
So My chart one and basically this is being used to render the chart now and basically first of all for all charts, it’s the same when we use the charts we have to specify a type and we want to start with a Don not chart here so let’s give it a type of donut and then already we can specify data and it’s really nice because it’s all following adjacent structure here which makes it.
Very easy to navigate through and define the necessary steps and variables. So coming to our data, we can define labels. And we will come to this in a minute. First of all, let me just let’s labels one here. Next, we can define the data sets because potentially we could have several sets on a chart.
So we will come to this labels one data, one colors, one in just a minute. Just ignore it for now. So after we are finished with the data sets, we can close the data tag here. So we’re closing this data stuff here, and then we move on with comma, and we can specify certain options and the options we can define stuff like, for example, a title. And for the title, we have, again, two options in this case.
Let me enter this a little bit. In this case, the question we want to answer with our donor chart. So in this case, as we are using a Donut chart, why not asking the question, do you like Donuts? And we can set the display of the title to true.
I think that’s it already for the Donut chart. So basically, we need to specify the type, the title. So basically the question we want to answer with this chart. And then now we have to come back to our labels, data and colors.
So basically, for the labels I just gave it or specified it as labels one. Let’s just create a variable labeled one here on the top, which we will hand in the values here. Yes. So do you like Donuts, yes or yes? And you will see what’s behind this in a minute.
so let’s get back to Adam. That is where we stopped. Let’s move to our index file.
The post How to leave just points without lines in ChartJS 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 & IE7+ unexpected behaviour with cached $objects
- jQuery animate horizontal div from off screen without scroll
- display jquery color picker on top rather than bottom
- Changing form select field with a link clicked on a different page
- Affect all elements that doesn't have an index of?
- Javascript/jQuery: Change li class and style depending on the IMG ALT inside
- Jquery select only what is in this DIV?
- Get/find javascript object by its parameter
- Search for text wrap with html
- Best Datagrid for Bootstrap/jQuery?
- How To Add a New Related Object in a Django Form
- MVC Post Json Error
- Jquery Droppable not working for Dynamically added DIVS
- How to set a php variable using a jQuery conditional test?
- How can I loop inside a loop and sort results from a JSON object via AJAX call?
- Use jQuery.data to get a boolean from a dom element?
- jQuery custom vertically scrolling UL bug
- bootstrap checkbox button event propagation issue
- Converting a list into a select with jquery
- Hide list items if more than a certain number exist
- Using jQuery inside image tag within .html() method
- window.open() add a rel="nofollow" attribute
- jQuery issue with .data() containing a space in its value
- Get all rows excluding a column jQuery
- changing the size of an image with css
- Blueimp File Upload: file is not deleting correctly from queue
- TinyMCE editor inside jQuery dialog autoscrolls top when unfocusing the editor
- Converting html page represented as text to dom object
- jQuery click event works only once (Beginner)
- Simple hover zoom thumbnail with jQuery
- Do we have a common gallery to show images and PDF?
- How to implement Facebook's `Drag Links/Photos Here`?
- How to enable or allow user to manually enter the date in JQuery datepicker field?
- Jquery autocomplete with multiple keywords, highlighting and partial matches
- Method autovivification
- jQuery transform both existing and dynamically created elements
- php - countdown timer getting value to jquery
- Using jQuery(this).next() to show/hide the next nested UL in a menu
- How to update an existing row with HTML on an existing JQuery Datatables?
- Bootstrap datepicker autoclose doesnt work
- jquery disable click over <object>
- How to amend Javascript for Progress bar to track scrolling on a horizontal website
- JQuery not working in Ajax load page
- Create a div dynamically in Javascript
- Chome autocomplete on text input prevents keydown event from firing (jquery)
- Any ideas how to replicate this inline dropdown menu using css/jquery
- create routing for multi module angular app
- KendoUI grid server filtering not getting data to controller
- Display multiple selectbox and radio button values values in div
- Jquery: Finding a 1 on a page and appending a class to an existing class in a row
- Jquery ajax to another controller/method on codeigniter getting Cross origin issue
- How to take the sum of the value of keys?
- Post of form append generated via jquery
- Show sub-menu on click
- Adding submit event on form prevents submit parameter from being included in HTTP POST
- javascript: Extened destroy method doesn't get called but super does get called
- How to avoid creating several if/statements and/or instances of function
- Validating if text exists on a jQuery wrapped set
- Difference between $(document).on('click') and $('p[class="classname"]').on('click')
- How can I improve my sites IE6/7 JS performance?
- How to handle nested views with Backbone.js?
- Konva js - Bind drag start event to a draggable element and not move it
- Render partial on click with Jquery append
- How to remove inputmask when an ajax form is submitted as FromData?
- I have a loop creating several Ajax calls. How can I tie the .then() responses to the correct elements that I create in the loop?
- WordPress Ajax Call -- WordPress User ID
- Preload all images in a directory using jQuery
- How to require jQuery in Node using Gulp?
- Inline edit in Kendo UI grid?
- Dynamically switching JQuery themes?
- checkbox styling plugin not working
- Why does jQuery not affect content generated after a Ajax call
- How to specify data type for datatable colums?
- On Radio Button show text area and store its value in an array
- Replace text of multiple nodes at once
- Prevent absolute pos. footer div shake when scrolling
- Replace multiple click handlers with a single click handler
- Mousewheel Scroll not working inside Div
- How can I get rid of the space between rows in a HTML table?
- Jquery input validation dependent on checkbox value
- Jquery slide from right to left
- How to make SpriteSpin responsive?
- JQuery Datepicker datetime issue parsing to @Html.EditorFor MVC3
- Return an array as result of jquery ajax function
- JQuery AJAX - How to refresh/reload page using a method GET call
- JQuery language drop-down selector
- How to prevent html5 video player play icon from disappearing in iPhone Safari
- Add JSON output to HTML ID
- Angular make a resquest after a response server
- jquery droppable -> avoid multiple drops of the same object
- Jquery: Each statement only affecting first item
- Getting Data from button click for Jquery
- Get a checkbox value in a different column
- How to Get Value Using Class
- JQuery Validation Help
- How do I make a Range selection spanning multiple elements?
- Toggle selected elemens class
- Display one div at a time
- jQuery validation, put error message below groups of checkboxes and radio buttons
- How can I scroll through div text with fixed container?
- How to filter emojis from string jquery/javascript?
- How to add the buttons from Button helper to the title (Fancybox 2)?
- how to load single pie chart on different pages
- jQuery - widest item on page
- Flip Menu with Fixed Top Menu
- Can I move HTML DOM object to a browser dialog to implement "detach" functionality
- combine plain JavaScript and jQuery together
- How to build my gulp file?
- jQuery UI Sortable and Table/Cell Size
- ajax- if I send an ajax request on a url, can i check in the php page if it is a request or the page has been opened?
- Submitted form via ajax always return TRUE of unchecked checkbox
- How to apply css, after Jquery adds a class?
- Why can't I use ES6 template literals with .css() method?
- getScript, loading multiple scripts in series?
- How to slide up when click any outside of div?
- How to read multi-level Json data by using jQuery?
- Cannot display bootstrap dialog with an asp.net mvc url.action link
- Injecting a tag having an attribute with colon in it using jquery
- Unexpected Token : when trying to parse a JSON string
- How to override existing Backbone Model method keeping other methods same
- Javascript - Changing button image depending on device
- jQuery doesn't returns the new data-attribute
- Bootstrap Grid sometimes started from right side in new row
- Hover on specific post should show the title of only that post
- Keep div aspect ratio within another div
- Iterate through JSON object list provided by ASP.NET webservice
- Client-Side Table Filtering
- Text editor selection settings to include "$" and "-"?
- jQuery UI Tabs Plugin Broke
- Symfony2 : AJAX request : How to handle authentication when needed?
- Adding a jQuery code to a PHP string
- Adding same item too many times to a list
- what is the correct Jquery document.ready wrap
- CSS navigation bar screen resolution
- Simple <ul> <li> HTML Structure : MegaMenu
- submit action is called twice on production server (RAILS)
- JQuery only allows one button with this code
- jquery replace label name with a variable
- Duplicate/Clone Javascript Object
- Creating a dynamic array within a dynamic array in JQuery
- jQuery scroll content with navigation
- How to send ruby script stdout, as it processes, line by line, to an iframe in rails 3.1?
- Make Accordion Close on second click JQUERY
- Disable specific scrollbar when mouse is in a section with a different scrollbar
- Dynamically Load Google Map AJAX Tutorial
- jQuery ajax call - Getting meaningful error messages
- Click event listener works just on the second time
- fineuploader with overall progressbar
- how to generate codeigniter's form_input using javascript
- how to use jquery.metro.js ? Unable to get it working?