|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | + |
| 4 | +<head> |
| 5 | + <title>Chart.js Error Bars Plugin</title> |
| 6 | + <script src="../node_modules/chart.js/dist/Chart.bundle.js" type></script> |
| 7 | + <script src="../build/Plugin.Errorbars.js"></script> |
| 8 | + <style> |
| 9 | + canvas { |
| 10 | + -moz-user-select: none; |
| 11 | + -webkit-user-select: none; |
| 12 | + -ms-user-select: none; |
| 13 | + } |
| 14 | + </style> |
| 15 | +</head> |
| 16 | + |
| 17 | +<body> |
| 18 | + <div id="container" style="width: 50%;"> |
| 19 | + <canvas id="canvas"></canvas> |
| 20 | + </div> |
| 21 | + |
| 22 | + <script> |
| 23 | + var color = Chart.helpers.color; |
| 24 | + var barChartData = { |
| 25 | + labels: ["January", "February", "March", "April"], |
| 26 | + datasets: [ |
| 27 | + { |
| 28 | + label: "Dataset 1", |
| 29 | + //backgroundColor: '#d95f02', |
| 30 | + borderColor: "#d95f02", |
| 31 | + borderWidth: 1, |
| 32 | + data: [56, 33, 78, 54], |
| 33 | + errorBars: { |
| 34 | + January: {plus: 15, minus: -34}, |
| 35 | + February: {plus: 15, minus: -3}, |
| 36 | + March: {plus: 35, minus: -14}, |
| 37 | + April: {plus: 45, minus: -4} |
| 38 | + }, |
| 39 | + yAxisID: "y-axis-1" |
| 40 | + }, |
| 41 | + { |
| 42 | + label: "Dataset 2", |
| 43 | + //backgroundColor: '#1b9e77', |
| 44 | + borderColor: "#1b9e77", |
| 45 | + borderWidth: 1, |
| 46 | + data: [100, 77, 33, 45], |
| 47 | + errorBars: { |
| 48 | + January: {plus: 15, minus: -34}, |
| 49 | + February: {plus: 5, minus: -24}, |
| 50 | + March: {plus: 20, minus: -4}, |
| 51 | + April: {plus: 45, minus: -20} |
| 52 | + }, |
| 53 | + yAxisID: "y-axis-2" |
| 54 | + } |
| 55 | + ] |
| 56 | + }; |
| 57 | + |
| 58 | + window.onload = function () { |
| 59 | + var ctx = document.getElementById("canvas").getContext("2d"); |
| 60 | + window.myBar = new Chart(ctx, { |
| 61 | + type: "bar", |
| 62 | + data: barChartData, |
| 63 | + options: { |
| 64 | + responsive: true, |
| 65 | + legend: { |
| 66 | + position: "top" |
| 67 | + }, |
| 68 | + title: { |
| 69 | + display: true, |
| 70 | + text: "Chart.js Error Bars Plugin" |
| 71 | + }, |
| 72 | + scales: { |
| 73 | + yAxes: [ |
| 74 | + { |
| 75 | + type: "linear", |
| 76 | + display: true, |
| 77 | + position: "left", |
| 78 | + id: "y-axis-1" |
| 79 | + }, |
| 80 | + { |
| 81 | + type: "linear", |
| 82 | + display: true, |
| 83 | + position: "right", |
| 84 | + id: "y-axis-2", |
| 85 | + gridLines: { |
| 86 | + drawOnChartArea: false |
| 87 | + } |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + plugins: { |
| 92 | + chartJsPluginErrorBars: { |
| 93 | + width: "60%" |
| 94 | + //color: 'darkgray' |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + }); |
| 99 | + }; |
| 100 | + </script> |
| 101 | +</body> |
| 102 | + |
| 103 | +</html> |
0 commit comments