|
9 | 9 | {{ parent() }}
|
10 | 10 |
|
11 | 11 | <link rel="stylesheet" href="{{ asset('css/vendor/datepicker.css') }}" />
|
12 |
| - <link rel="stylesheet" href="{{ asset('css/jqplot/jquery.jqplot.min.css', 'debug') }}" /> |
13 |
| - <link rel="stylesheet" href="{{ asset('css/jquery-ui/jquery-ui.min.css', 'debug') }}" /> |
14 | 12 | {% endblock %}
|
15 | 13 |
|
16 | 14 | {% block content %}
|
|
19 | 17 | </div>
|
20 | 18 |
|
21 | 19 | <div id="barchart" style="width:700px; height:600px;" data-href="{{ uri.base.path }}activity/user/{{ project.alias }}/query"></div>
|
| 20 | + <div id="new-barchart"></div> |
22 | 21 |
|
23 | 22 | <br />
|
24 | 23 | <h2>Chart Options</h2>
|
25 | 24 | <div class="form-inline">
|
26 | 25 | <fieldset>
|
27 |
| - <label>Period</label> |
28 |
| - <select id="period" name="period" class="input" size="1"> |
| 26 | + <label for="period">Period</label> |
| 27 | + <select id="period" name="period" class="form-control form-control-sm d-inline-block w-auto" size="1"> |
29 | 28 | <option value="1" selected="selected">7 Days</option>
|
30 | 29 | <option value="2">30 Days</option>
|
31 | 30 | <option value="3">90 Days</option>
|
32 | 31 | <option value="4">1 Year</option>
|
33 | 32 | <option value="5">Custom Period</option>
|
34 | 33 | </select>
|
35 | 34 |
|
36 |
| - <label>Type</label> |
37 |
| - <select id="type" name="type" class="input-small" size="1"> |
| 35 | + <label for="type">Type</label> |
| 36 | + <select id="type" name="type" class="form-control form-control-sm d-inline-block w-auto" size="1"> |
38 | 37 | <option value="0" selected="selected">All</option>
|
39 | 38 | <option value="1">Tracker</option>
|
40 | 39 | <option value="2">Test</option>
|
41 | 40 | <option value="3">Code</option>
|
42 | 41 | </select>
|
43 | 42 |
|
44 |
| - <button class="btn btn-primary" id="dataUpdate">Update Chart</button> |
| 43 | + <button type="button" class="btn btn-primary btn-sm" id="dataUpdate">Update Chart</button> |
45 | 44 | <br />
|
46 | 45 | <br />
|
47 | 46 | <div id="hidedates" class="form-inline">
|
48 |
| - <label>Start Date</label> |
| 47 | + <label for="start_date">Start Date</label> |
49 | 48 | <input id="start_date" class="datepicker-input input-small" type="text" />
|
50 |
| - <label>End Date</label> |
| 49 | + <label for="end_date">End Date</label> |
51 | 50 | <input id="end_date" class="datepicker-input input-small" type="text" />
|
52 | 51 | </div>
|
53 | 52 |
|
|
60 | 59 |
|
61 | 60 | <script src="{{ asset('js/vendor/datepicker.js') }}"></script>
|
62 | 61 | <script src="{{ asset('js/vendor/datepicker/locales/en-GB.js') }}"></script>
|
63 |
| - <script src="{{ asset('js/jqplot/jquery.jqplot.min.js', 'debug') }}"></script> |
64 |
| - <script src="{{ asset('js/jqplot/jqplot.barRenderer.js', 'debug') }}"></script> |
65 |
| - <script src="{{ asset('js/jqplot/jqplot.categoryAxisRenderer.js', 'debug') }}"></script> |
66 |
| - <script src="{{ asset('js/jqplot/jqplot.pointLabels.js', 'debug') }}"></script> |
67 |
| - <script src="{{ asset('js/jqplot/jqplot.highlighter.js', 'debug') }}"></script> |
68 |
| - <script src="{{ asset('js/jqplot/barchart.js', 'debug') }}"></script> |
69 |
| - <script src="{{ asset('js/jquery-ui/jquery-ui.min.js', 'debug') }}"></script> |
| 62 | + <script src="{{ asset('js/vendor/chart.js') }}"></script> |
70 | 63 |
|
71 | 64 | <script type="text/javascript">
|
72 |
| - (function ($) { |
73 |
| - $(document).ready(function () { |
74 |
| - var barchart = new $.JQPLOTBarchart('barchart', 'barchart', 'horizontal', true, '10'); |
75 |
| -
|
76 |
| - $('#dataUpdate').click(function () { |
77 |
| - // add the form variables to the URL |
78 |
| - var chartContainer = $('#barchart'), |
79 |
| - period = $('#period').val(), |
80 |
| - type = $('#type').val(), |
81 |
| - startdate = $('#start_date').val(), |
82 |
| - enddate = $('#end_date').val(), |
83 |
| - href = '{{ uri.base.path }}activity/user/{{ project.alias }}/query?period=' + period + '&activity_type=' + type; |
84 |
| -
|
85 |
| - if (period == 5) { |
86 |
| - href += '&startdate=' + startdate + '&enddate=' + enddate; |
87 |
| - } |
88 |
| -
|
89 |
| - chartContainer.empty(); |
90 |
| - chartContainer.attr('data-href', href); |
91 |
| -
|
92 |
| - barchart = new $.JQPLOTBarchart('barchart', 'barchart', 'horizontal', true, '10'); |
93 |
| - }); |
| 65 | + document.getElementById('hidedates').style.display = 'none'; |
| 66 | +
|
| 67 | + document.getElementById('period').addEventListener('change', (event) => { |
| 68 | + if (event.target.value === '5') { |
| 69 | + document.getElementById('hidedates').style.removeProperty('display'); |
| 70 | + } else { |
| 71 | + document.getElementById('hidedates').style.display = 'none'; |
| 72 | + } |
| 73 | + }); |
94 | 74 |
|
95 |
| - $('#hidedates').hide(); |
| 75 | + const ctx = document.getElementById('new-barchart'); |
96 | 76 |
|
97 |
| - $('#period').change(function () { |
98 |
| - if ($(this).val() == 5) { |
99 |
| - $('#hidedates').show(); |
100 |
| - } else { |
101 |
| - $('#hidedates').hide(); |
| 77 | + const myChart = new Chart(ctx, { |
| 78 | + type: 'bar', |
| 79 | + data: {}, |
| 80 | + options: { |
| 81 | + indexAxis: 'y', |
| 82 | + scales: { |
| 83 | + x: { |
| 84 | + beginAtZero: true |
102 | 85 | }
|
| 86 | + }, |
| 87 | + plugins: { |
| 88 | + title: { |
| 89 | + display: true, |
| 90 | + text: 'Custom Chart Title' |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + }); |
| 95 | +
|
| 96 | + function updateChart(){ |
| 97 | + const period = document.getElementById('period').value; |
| 98 | + const type = document.getElementById('type').value; |
| 99 | + const start_date = document.getElementById('start_date').value; |
| 100 | + const end_date = document.getElementById('end_date').value; |
| 101 | +
|
| 102 | + // add the form variables to the URL |
| 103 | + let href = '{{ uri.base.path }}activity/user/{{ project.alias }}/query?period=' + period + '&activity_type=' + type; |
| 104 | +
|
| 105 | + if (period === '5') { |
| 106 | + href += '&startdate=' + start_date + '&enddate=' + end_date; |
| 107 | + } |
| 108 | +
|
| 109 | + fetch(href) |
| 110 | + .then((response) => response.json()) |
| 111 | + .then((json) => { |
| 112 | + console.log(json); |
| 113 | + myChart.data = { |
| 114 | + labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], |
| 115 | + datasets: [ |
| 116 | + { |
| 117 | + label: '# of Votes', |
| 118 | + data: [12, 19, 3, 5, 2, 3], |
| 119 | + borderWidth: 1 |
| 120 | + } |
| 121 | + ] |
| 122 | + }; |
| 123 | + myChart.update(); |
103 | 124 | });
|
104 |
| - }); |
105 |
| - })(jQuery); |
| 125 | + } |
| 126 | +
|
| 127 | + // Populate the chart with initial data and set up the click event for any modifications |
| 128 | + document.getElementById('dataUpdate').addEventListener('click', updateChart); |
| 129 | + updateChart(); |
106 | 130 |
|
107 | 131 | const datepickerElements = document.querySelectorAll('.datepicker-input');
|
108 | 132 |
|
|
0 commit comments