Chart.js – Color

Chart.js – Color ”; Previous Next Chart.js library provides us various format with the help of which we can easily supply the colors to the chart or graph options. You can specify the color as string in the following notations − Hexadecimal RGB HSL Chart.js will use the global default color, if you haven’t specified any color and if the chart needed color. The following table provides the 3 color options that are stored in “Chart.defaults” − Name Type Default Description backgroundColor Color rgba(0, 0, 0, 0.1) Background color borderColor Color rgba(0, 0, 0, 0.1) Border color Color Color #666 Font color Example Let’s take an example in which we will set the color in our chart − <!DOCTYPE> <html> <head> <meta charset- “UTF-8″ /> <meta name=”viewport” content=”width=device-width, initial-scale=1″ /> <title>chart.js</title> </head> <body> <canvas id=”chartId” aria-label=”chart” height=”350″ width=”580″></canvas> <script src=”https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.1.1/chart.min.js”></script> <script> var chrt = document.getElementById(“chartId”).getContext(“2d”); var chartId = new Chart(chrt, { type: ”bar”, data: { labels: [“HTML”, “CSS”, “JAVASCRIPT”, “CHART.JS”, “JQUERY”, “BOOTSTRP”], datasets: [{ label: “online tutorial subjects”, data: [20, 40, 30, 35, 30, 20], backgroundColor: [”yellow”, ”aqua”, ”pink”, ”lightgreen”, ”lightblue”, ”gold”], borderColor: [”red”, ”blue”, ”fuchsia”, ”green”, ”navy”, ”black”], borderWidth: 2, }], }, options: { responsive: false, }, }); </script> </body> </html> Output This HTML code will produce the following chart having graph elements with different colors − Print Page Previous Next Advertisements ”;

Chart.js – Radar Chart

Chart.js – Radar Chart ”; Previous Next Chart.js radar chart, as the name implies, is used to show multiple data points and the difference between those data points. With the help of radar chart, we can easily compare the points of two or more different datasets. Following are the namespaces to be used in radar chart for dataset properties − data.datasets[index] − It provides options for this dataset only. options.datasets.line − It provides options for all the line datasets. options.elements.line − It provides options for all the line elements. options.elements.point − It provides options for all the point elements. Options − It provides options for the whole chart We need to use type: “radar” for creating the radar chart. Example Let’s take an example with the help of which we will create a radar chart − <!DOCTYPE> <html> <head> <meta charset- “UTF-8″ /> <meta name=”viewport” content=”width=device-width, initial-scale=1″ /> <title>chart.js</title> </head> <body> <canvas id=”chartId” aria-label=”chart” height=”350″ width=”580″></canvas> <script src=”https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.1.1/chart.min.js”></script> <script> var chrt = document.getElementById(“chartId”).getContext(“2d”); var chartId = new Chart(chrt, { type: ”radar”, data: { labels: [“HTML”, “CSS”, “JAVASCRIPT”, “CHART.JS”, “JQUERY”, “BOOTSTRP”], datasets: [{ label: “online tutorial subjects”, data: [20, 40, 33, 35, 30, 38], backgroundColor: [”lightgrey”], pointBackgroundColor: [”yellow”, ”aqua”, ”pink”, ”lightgreen”, ”lightblue”, ”gold”], borderColor: [”black”], borderWidth: 1, pointRadius: 6, }], }, options: { responsive: false, elements: { line: { borderWidth: 3 } } }, }); </script> </body> </html> Output Print Page Previous Next Advertisements ”;

Chart.js – Introduction

Chart.js – Introduction ”; Previous Next What is Chart.js? Chart.js, a popular open-source data visualization framework, enables us to generate the following chart types − Scatter Plot Line Chart Bar Chart Pie Chart Donut Chart Bubble Chart Area Chart Radar Chart Mixed Chart Chart.js is a community-maintained free JavaScript library for making HTML-based charts. While working with Chart.js the user just needs to indicate where on page he wants the graph to be displayed and what sort of graph he wants. Once done with that, the user needs to supply Chart.js with data, labels, and some other settings. Rest of the things will be managed by library itself. Chart.js Features Below are the features of Chart.js − Open-source free library − Chart.js is a free open-source community-maintained library which you can use either in offline or online mode. Canvas − It provides us canvas element for dynamic images. Built-in charts − It provides the user various built-in charts such as Line, Bar, Horizontal Bar, Radar, Bubble etc., to be used. Extendable to Custom Charts − You can create a custom charts using Chart.js library. Supports Modern Browsers − Chart.js supports all the modern browsers. Extensive Documentation − Chart.js documentation is well organized that provides detailed information about each feature. It makes it easy to understand and use even for novice users. Chart.js – Advantages The advantages of Chart.js are as follows − Chart.js provides the user 6 different animated views to visualize the data. It provides lots of customization options as well as interactivity extensions. It provides various types of interactive charts to display data. It is totally free to use. The update, remove, and modification of data from a chart is easy and hustle-free. Chart.js due to its simple structure can store maximum data in minimum space. Chart.js uses several y-axes due to which it can stores multiple data in a single graph. Chart.js charts are fully responsive. Many plugins are available for use via NPM. In fact, you can write your own plugins as well. Chart.js – Limitations Apart from various advantages, Chart.js is having the following limitations − Chart.js displays only similar type of data with variations. An installation of Chart.js only supports display of graphs and charts. It lacks the flexibility offered by other options. The canvas element is bitmap based. It shares the same issues as non-vector formats. Comparison with Google Chart and Plotly.js Chart.js has main competition with two other JavaScript charting libraries namely plotly.js and Google chart. Google chart uses web services to create charts. Although it offers maximum charts, but they do not offer enough customization and interactivity. On the other hand, Chart.js, is a free JavaScript charting library, which provides less charts but with great customization and interactivity options. To summarize if you need charts without any complex interaction then go for Google Charts. And if you need simple set of charts with least configurations then Chart.js would be the choice for you. Chart.js and Plotly.js both are open-source free to use tools for charting. Chart.js is animated, HTML5 based and responsive whereas Plotly.js is an online chart editor that supports MatLab, Python, and R programming languages with full interactivity. The documentation of chart.js is easy than the plotly.js. Print Page Previous Next Advertisements ”;