chart.js

ChartJS hide labels on small screen sizes

﹥>﹥吖頭↗ 提交于 2020-01-04 14:13:35
问题 I have a problem hiding xAxes and yAxes labels on small screen sizes (mobile phones). I know there is this option: options: { scales: { xAxes: [{ ticks:{ display: false } }]; } } But if i use it in the onResize function like this var ctx = document.getElementById("chart"); var myChart = new Chart(ctx, { //chart data and options, onResize: function(myChart, size) { if (size.height < 140) { options: { scales: { xAxes: [{ ticks:{ display: false } }]; } } } }); But it does not work on resize. Is

How to add a dataset toggle to Chart.js?

落花浮王杯 提交于 2020-01-04 04:30:08
问题 I'm using Chart.js to create a line chart. I would like to have four different datasets that will all be visibile by default, but can be toggled on and off by clicking a button. How can this be achieved? I can't seem to find an answer in the documentation. .addData() , .removeData() and .update() all seem to be used for adding or removing values to existing datasets, but not adding or removing entire datasets. I would think this would be fairly commonly used feature but I can't find an answer

How can I change color of only one column in Barchart using Chart.js

情到浓时终转凉″ 提交于 2020-01-04 03:56:28
问题 js http://www.chartjs.org/docs/#bar-chart I am using the basic sample: HTML <canvas id="canvas" height="450" width="600"></canvas> JS var data = { labels: ["January", "February", "March", "April", "May", "June", "July"], datasets: [ { label: "My First dataset", fillColor: "rgba(220,220,220,0.5)", strokeColor: "rgba(220,220,220,0.8)", highlightFill: "rgba(220,220,220,0.75)", highlightStroke: "rgba(220,220,220,1)", data: [65, 59, 80, 81, 56, 55, 40] } ] }; window.onload = function(){ var ctx =

ChartJS How to set max labels for X axis?

别来无恙 提交于 2020-01-04 01:20:13
问题 I receive data for chart from an array , where I stored dates from 2016 , 1 to 2018 , 12 . In chart it displays all month for 3 years. But I need to display only for 1 year. Any ideas? Here i'm passing an array and changing unit for month, also displayFormats chartHour.config.data.datasets[0].data = array chartHour.config.options.scales.xAxes[0].time = { unit: "month", stepSize: 1, displayFormats: { month: "MMM", }, } 回答1: You can do it by defining the min and max values under the time key.

Multiple Range Highlighting of Background in Chart.js

眉间皱痕 提交于 2020-01-03 18:59:32
问题 From this question I'm looking to turn into a multiple range highlight But there 1 annoying bug I didn't success to solve background are superposing, if you uncheck a dataset on the top, alpha change Here my work so far: https://jsfiddle.net/742zut83/588/ Why is custom draw function executed for each dataset? One highlights done originalLineDraw is returned draw : function() { var chart = this.chart; // Get the object that determines the region to highlight. var yHighlightRanges = chart

Chart.js moment locale

限于喜欢 提交于 2020-01-03 15:34:24
问题 I'm building an Angular 2 app and use Chart.js 2.0 to display 'time' data. Unfortunately I am not able to change the locale of moment.js. I npm installed moment and import moment.js and pl.js using SystemJS, but Chart.js complains that moment.js has to be loaded before Chart.js (not sure how to accomplish that, in every source file moment is declared before chartjs). Then I tried the Chart.bundle.min.js (with moment included), which works but only in english. I am not able to change the

How can I increase the size of the pie (Chart.JS)?

假装没事ソ 提交于 2020-01-03 08:37:10
问题 I'm generating a pie chart with legend that looks like so: As you can perceive, the pie is pitifully puny. I prefer it to be twice as tall and twice as wide. Here is the code I am using: var formatter = new Intl.NumberFormat("en-US"); Chart.pluginService.register({ afterDatasetsDraw: function (chartInstance) { var ctx = chartInstance.chart.ctx; ctx.font = Chart.helpers.fontString(14, 'bold', Chart.defaults.global.defaultFontFamily); ctx.textAlign = 'center'; ctx.textBaseline = 'bottom'; ctx

How can I show JSON data in Chart.js with Javascript if static values are working but dynamic from mySQL are not?

橙三吉。 提交于 2020-01-02 20:18:55
问题 I have JSON data in the following form: { "labels": ["12.11.2016", "13.11.2016", "14.11.2016", ...], "temperature": ["12", "35", "27", ...], "humidity": ["56", "70", "87", ...] } and want to show it in Chart.js. I already found this example but it somehow isn't working... My code for Chart.js is the following: <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta http-equiv=

Chart js: Update line chart having two data sets

安稳与你 提交于 2020-01-02 09:19:26
问题 I want to update a line chart in chart js with two data sets. I've somehow managed to empty the chart and then able to fill in one of the data set. but unable to make both data sets working. here's the code. ajaxRequest( { url: 'reports/updateChart/?filter=true', method: 'post', data: data }, function (response) { /*refresh the tables with the new data sets*/ removeData(myChart); let label = [1, 234, 234, 234, 234, 234, 234, 34, 234, 23, 23, 41, 3, 2, 4]; let data = [234, 234, 5, 23, 34, 234,

Getting chart js bar chart to fill window

旧时模样 提交于 2020-01-02 07:44:29
问题 I have a chart js bar chart that draws within the canvas: <canvas id="chart" width="800" height="400"></canvas> However I would like the chart to fit the size of the current window. I have tried: <canvas id="chart" width="100%" height="400"></canvas> but it does not like it. I could get the window width using window.innerWidth but is there any reason why the 100% does not work? 回答1: Please see the post: Chart.js canvas resize . There are actually two answers that are really good solutions