chart.js

how to display data values on Chart.js

混江龙づ霸主 提交于 2019-12-27 10:37:28
问题 I would like to ask if it's possible using Chart.js to display data values? I want to print the graph. Thanks for any advice. 回答1: Late edit: there is an official plugin for Chart.js 2.7.0+ to do this: https://github.com/chartjs/chartjs-plugin-datalabels Original answer: You can loop through the points / bars onAnimationComplete and display the values Preview HTML <canvas id="myChart1" height="300" width="500"></canvas> <canvas id="myChart2" height="300" width="500"></canvas> Script var

How to set width of bar dynamically in chart.js?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-26 10:19:31
问题 for one value the bar width is width of canvas so i want only to change the width of bar how to fix the width of bar size ? 回答1: Check this out barThickness Manually set width of each bar in pixels. If not set, the base sample widths are calculated automatically so that they take the full available widths without overlap. Then, the bars are sized using barPercentage and categoryPercentage. Your code should be something like this: var myBarChart = new Chart(ctx, { type: 'bar', data: data,

How to display pie slice data and tooltip together using chart.js

荒凉一梦 提交于 2019-12-26 05:38:50
问题 Can we display data in pie chart slice and also tolltip like the above image using chart.js? Updated: Here is my code in php page. printf( '<table>' ); echo '<tr><td style="text-align: right;"><canvas id="pie-canvas-' . $canvasId . '" width=256px height=257px ></canvas></td><td style="text-align: left;width:360px;" id="legend" class="chart-legend"></td></tr>'; echo '<script type="text/javascript">drawPie(' . $canvasId . ', ' . $data .', ' . $legend . ');</script>'; printf( '</table>' );

How to display pie slice data and tooltip together using chart.js

情到浓时终转凉″ 提交于 2019-12-26 05:38:02
问题 Can we display data in pie chart slice and also tolltip like the above image using chart.js? Updated: Here is my code in php page. printf( '<table>' ); echo '<tr><td style="text-align: right;"><canvas id="pie-canvas-' . $canvasId . '" width=256px height=257px ></canvas></td><td style="text-align: left;width:360px;" id="legend" class="chart-legend"></td></tr>'; echo '<script type="text/javascript">drawPie(' . $canvasId . ', ' . $data .', ' . $legend . ');</script>'; printf( '</table>' );

Object.values not seperated by parentheses / Chartjs only displays first element of array

。_饼干妹妹 提交于 2019-12-25 18:31:59
问题 after jumping a few hurdles here with your wonderful help, I have a new problem: I am taking a json object and want to visualize it in chart.js. It almost works(tm), but only the first data point is shown. I suppose this has something to do with the missing apostrophes in the "total" array, kindly see attached screenshot from firefox. So, two questions: why is the "total" array structured differently from the "labels" array? And how do I make this work? console.log('hi'); $(document).ready

Animation chart js (line), animate chart drawing line by line

别等时光非礼了梦想. 提交于 2019-12-25 18:17:01
问题 Is there a way to extend the current chart.js so that the animation drawing doesn't animate the whole chart, but drawing the chart line by line with animation (ease) ? 回答1: You can use the onAnimationComplete callback to change the data and call update() ... data: [0, 0, 0, 0, 0, 0, 0] } ] }; var data2 = [28, 48, 40, 19, 86, 27, 90]; var done = false; var myLineChart = new Chart(ctx).Line(data, { animationEasing: 'linear', onAnimationComplete: function () { if (!done) { myLineChart.datasets[1

How to modify chartjs tooltip to add customized attribute

独自空忆成欢 提交于 2019-12-25 14:00:46
问题 How I have to edit the tooltip template that i can add customized attributes from my json file ? Below the example: ChartJS Example In the x-axis are the Months with the first letter, but in the tooltip i want to show the first three letters of the month - How can i do this ? EDIT: My JSON File: {"modules":[{ "name":"Chart 1", "link":"www.google.com", "type":"Bar", "series":"SeriesA", "data":[[20,40,50,40,20,20,20,20,20,20,20,20]], "labels":["M","J","J","A","S","O","N","D","J","F","M","A","M"

Array not working correctly in Chartjs

烂漫一生 提交于 2019-12-25 09:17:44
问题 I'm doing a data integration project with my external ERP(Tally.ERP9) with PHP(version 7),JQuery and ChartJS. where I'm pulling data from Tally.ERP9 through ODBC and fetched the rows as array. I also converted PHP array Variable as JavaScript array Variable using the below code <script type="text/javascript"> var test = '<?php $stks = array_values($stocks); echo json_encode($stks); ?>'; var test2 = '<?php $qtys = array_values($qty); $armap = array_map('intval', $qtys); echo json_encode($armap

Chart.js not working properly to draw lines when is only 1 bar

匆匆过客 提交于 2019-12-25 09:06:28
问题 I want to do this chart: As you can see the lines ( Meta and Rango de aceptación ) were drawed like a points. I believe this is because I only have one bar and in another charts I was made with 2 bars I get the lines drawed like a line. This is the code, what I'm doing wrong? <canvas id="myChart2016_5857751099b04" width="500" height="500" style="display: block; width: 500px; height: 500px;"></canvas> <script style="text/javascript"> var ctx2016_5857751099b04 = document.getElementById(

passing each element of array in the labels of char.js

旧城冷巷雨未停 提交于 2019-12-25 09:05:00
问题 i am using chart.js i want to dynamically update label of my bar chart i have an array in javascript that takes it values from ajax now the issue is i want to pass each element of array in the label labels: [array[0],array[1],array[2],array[3],array[4]], this is what am i doing i m hard-coding each element of array but this is not what i wanted i want to display each element of array dynamically. I was thinking to take the length of array and then loop through the array till its length but