| 28468 |
tejbeer |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
| 30220 |
amit.gupta |
3 |
import com.spice.profitmandi.common.model.*;
|
|
|
4 |
import org.springframework.stereotype.Component;
|
|
|
5 |
|
| 28468 |
tejbeer |
6 |
import java.time.LocalDate;
|
|
|
7 |
import java.time.LocalDateTime;
|
|
|
8 |
import java.time.format.DateTimeFormatter;
|
|
|
9 |
import java.util.ArrayList;
|
|
|
10 |
import java.util.LinkedHashSet;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
|
|
13 |
import java.util.Map.Entry;
|
|
|
14 |
|
|
|
15 |
@Component
|
|
|
16 |
public class ChartServiceImpl implements ChartService {
|
|
|
17 |
|
|
|
18 |
@Override
|
|
|
19 |
public ChartModel createChart(int monthValue, Map<String, List<Double>> sortedBrandValue, List<String> colorList,
|
| 30220 |
amit.gupta |
20 |
List<String> borderList, String title) {
|
| 28468 |
tejbeer |
21 |
|
|
|
22 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
23 |
|
|
|
24 |
LinkedHashSet<String> labels = new LinkedHashSet<String>();
|
|
|
25 |
|
|
|
26 |
for (int i = monthValue; i >= 0; i--) {
|
|
|
27 |
|
|
|
28 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
| 30220 |
amit.gupta |
29 |
labels.add(startMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
|
| 28468 |
tejbeer |
30 |
}
|
|
|
31 |
|
| 30220 |
amit.gupta |
32 |
return createChartWithLabels(labels, sortedBrandValue, colorList,
|
|
|
33 |
borderList, title);
|
|
|
34 |
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
@Override
|
|
|
38 |
public ChartModel createChartWithLabels(LinkedHashSet<String> labels, Map<String, List<Double>> sortedBrandValue, List<String> colorList, List<String> borderList, String title) {
|
|
|
39 |
|
| 28468 |
tejbeer |
40 |
List<DatasetModel> datasets = new ArrayList<>();
|
|
|
41 |
|
|
|
42 |
int i = 0;
|
|
|
43 |
|
|
|
44 |
for (Entry<String, List<Double>> brandValue : sortedBrandValue.entrySet()) {
|
|
|
45 |
|
|
|
46 |
DatasetModel lmsModel = new DatasetModel();
|
|
|
47 |
lmsModel.setLabel(brandValue.getKey());
|
|
|
48 |
lmsModel.setBackgroundColor(colorList.get(i));
|
|
|
49 |
|
|
|
50 |
lmsModel.setData(brandValue.getValue());
|
|
|
51 |
|
|
|
52 |
lmsModel.setType("line");
|
|
|
53 |
lmsModel.setOrder(1);
|
|
|
54 |
lmsModel.setFill("false");
|
|
|
55 |
lmsModel.setBorderColor(borderList.get(i));
|
|
|
56 |
datasets.add(lmsModel);
|
|
|
57 |
|
|
|
58 |
i++;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
DataModel dm = new DataModel();
|
|
|
62 |
dm.setDatasets(datasets);
|
|
|
63 |
dm.setLabels(labels);
|
|
|
64 |
|
|
|
65 |
LegendModel lm = new LegendModel();
|
|
|
66 |
lm.setPosition("top");
|
|
|
67 |
|
|
|
68 |
Tooltips tooltips = new Tooltips();
|
|
|
69 |
tooltips.setBodyFontSize(15);
|
|
|
70 |
tooltips.setTitleFontSize(15);
|
|
|
71 |
tooltips.setMode("index");
|
|
|
72 |
tooltips.setIntersect(false);
|
|
|
73 |
tooltips.setBackgroundColor("rgba(0, 0, 0, .5)");
|
|
|
74 |
|
|
|
75 |
HoverModel hover = new HoverModel();
|
|
|
76 |
hover.setIntersect(false);
|
|
|
77 |
hover.setMode("index");
|
|
|
78 |
|
|
|
79 |
TitleModel tm = new TitleModel();
|
| 28473 |
tejbeer |
80 |
tm.setText(title);
|
| 28468 |
tejbeer |
81 |
tm.setDisplay(true);
|
|
|
82 |
tm.setFontSize(20);
|
|
|
83 |
tm.setFontColor("#111");
|
|
|
84 |
|
|
|
85 |
OptionsModel om = new OptionsModel();
|
|
|
86 |
om.setResponsive(true);
|
|
|
87 |
om.setLegend(lm);
|
|
|
88 |
om.setTitle(tm);
|
|
|
89 |
om.setTooltips(tooltips);
|
|
|
90 |
om.setHover(hover);
|
|
|
91 |
|
|
|
92 |
ChartModel cm = new ChartModel();
|
|
|
93 |
|
|
|
94 |
cm.setType("line");
|
|
|
95 |
cm.setData(dm);
|
|
|
96 |
cm.setOptions(om);
|
|
|
97 |
|
|
|
98 |
return cm;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
}
|