- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsers.java
More file actions
Latest commit
89 lines (86 loc) · 3.07 KB
/
Copy pathUsers.java
File metadata and controls
89 lines (86 loc) · 3.07 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
packagefinalproject;
/**
*
* @author shlok
*/
importjava.awt.Color;
importjava.io.IOException;
importjava.sql.Connection;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
importorg.knowm.xchart.PieChart;
importorg.knowm.xchart.PieChartBuilder;
importorg.knowm.xchart.XChartPanel;
importorg.knowm.xchart.demo.charts.ExampleChart;
importorg.knowm.xchart.style.PieStyler.AnnotationType;
importorg.knowm.xchart.style.Styler;
importorg.knowm.xchart.style.Styler.ChartTheme;
importstaticorg.knowm.xchart.style.Styler.LegendPosition.InsideNW;
publicclassUsersimplementsExampleChart<PieChart> {
publicXChartPanelgetPanel() throwsIOException {
ExampleChart<PieChart> exampleChart = newUsers();
PieChartchart = exampleChart.getChart();
XChartPanelpanel=newXChartPanel(chart);
returnpanel;
}
@Override
publicPieChartgetChart() {
Connectioncon = DbConnect.getConnection();
// Create Chart
PieChartchart =
newPieChartBuilder()
.width(1366)
.height(748)
.title("USERS IN THE LIBRARY")
.theme(ChartTheme.Matlab)
.build();
// Customize Chart
chart.getStyler().setLegendVisible(true);
chart.getStyler().setAnnotationDistance(1.5);
chart.getStyler().setPlotContentSize(.7);
chart.getStyler().setPlotBackgroundColor(newColor(229,229,229));
chart.getStyler().setCircular(true);
chart.getStyler().setStartAngleInDegrees(90);
chart.getStyler().setToolTipsEnabled(true);
chart.getStyler().setToolTipType(Styler.ToolTipType.xAndYLabels);
chart.getStyler().setLegendPosition(InsideNW);
//chart.getStyler().set
/*Color[] sliceColors =
new Color[] {
new Color(127,127,127),
new Color(229,248,255),
new Color(25,81,102),
};*/
// chart.getStyler().setSeriesColors(sliceColors);
chart.getStyler().setAnnotationType(AnnotationType.Value);
// Series
ArrayList<String> xData=newArrayList<>();
ArrayList<Integer> yData=newArrayList<>();
try {
Statementstatement = con.createStatement();
ResultSetresultSet = statement.executeQuery("SELECT * FROM users");
inti = 0;
while (resultSet.next())
{
xData.add(resultSet.getString("USERS"));
yData.add(Integer.parseInt(resultSet.getString("VALUE")));
System.out.println(xData.get(i)+yData.get(i).toString());
chart.addSeries(xData.get(i),yData.get(i));
i++;
}
}
catch (NumberFormatException | SQLExceptione)
{
System.out.println(e);
}
//chart.addSeries(xData,yData);
returnchart;
}
}