-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphScript.js
More file actions
144 lines (132 loc) · 3.75 KB
/
Copy pathGraphScript.js
File metadata and controls
144 lines (132 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Initializing Product List:
// This list should be loaded from a file or database
const roupas = ["Camisas", "Calças"]
const joias = ["Brincos","Cordões"]
const cosméticos = ["Perfume"]
const camisas = ["Camisa1","Camisa2"]
const calças = ["Calça1", "Calça2", "Calça3"]
const brincos = ["Brinco1","Brinco2"]
const cordões = ["Cordão1","Cordão2"]
const perfumes = ["Perfume1", "Perfume2"]
// Sales data by month
const data = {
"Camisa1": [450, 500, 400, 450],
"Camisa2": [400, 200, 100, 500],
"Calça1": [100, 250, 300, 450],
"Calça2": [100, 400, 100, 234],
"Calça3": [621, 250, 567, 400],
"Brinco1": [100, 100, 300, 100],
"Brinco2": [210, 200, 200, 500],
"Cordão1": [100, 400, 150, 450],
"Cordão2": [200, 200, 650, 400],
"Perfume1": [100, 400, 500, 100],
"Perfume2": [550, 200, 150, 300]
}
const calendar = [
'January',
'February',
'March',
'April'
]
var chart =Highcharts.chart('Graph', {
xAxis: {
type: 'category'
},
title: {
text: 'Sales by Month for:'
},
xAxis: {
categories: [
'January',
'February',
'March',
'April'
]
},
yAxis: {
min: 0,
title: {
text: 'Ventas'
}
},
series: [{
type: 'column',
name: 'Ventas',
data: [
['January', 35],
['February', 45],
['March', 29],
['April', 29]
],
keys: ['name', 'y']
}],
});
function updateProduct(){
var categoria = document.getElementById("Categoria").value;
var updater = "";
if (categoria == "Roupas"){
for (var item of roupas) {
updater += "<option>" + item + "</option>"
}
}
else if (categoria == "Joias"){
for (var item of joias) {
updater += "<option>" + item + "</option>"
}
}
else if (categoria == "Cosméticos"){
for (var item of cosméticos) {
updater += "<option>" + item + "</option>"
}
}
document.getElementById("Produto").innerHTML = updater;
}
function updateBrand(data){
var produto = document.getElementById("Produto").value;
var updater = "";
if (produto == "Camisas"){
for (var item of camisas) {
updater += "<option>" + item + "</option>"
}
}
else if (produto == "Calças"){
for (var item of calças) {
updater += "<option>" + item + "</option>"
}
}
else if (produto == "Brincos"){
for (var item of brincos) {
updater += "<option>" + item + "</option>"
}
}
else if (produto == "Cordões"){
for (var item of cordões) {
updater += "<option>" + item + "</option>"
}
}
else if (produto == "Perfume"){
for (var item of perfumes) {
updater += "<option>" + item + "</option>"
}
}
document.getElementById("Marca").innerHTML = updater;
}
function updateGraph(calendar, data){
// The data comes from the number of sales for a specific brand
var brand = document.getElementById("Marca").value;
var updater = []
for (var i = 0 ; i<calendar.length ;i++){
updater[i]=[calendar[i],data[brand][i]]
}
console.log(updater)
//update values in chart
for (var sales in data[brand]){
chart.series[0].setData(updater);
}
// Redraw chart
chart.redraw();
}
// Event listeners for selection change
document.getElementById("Categoria").addEventListener("input",function(){updateProduct();updateBrand();updateGraph(calendar,data)});
document.getElementById("Produto").addEventListener("input",function(){updateBrand();updateGraph(calendar,data)});
document.getElementById("Marca").addEventListener("input",function(){updateGraph(calendar,data)});