-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpenditureDistribution.java
65 lines (60 loc) · 2.04 KB
/
ExpenditureDistribution.java
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
/*
* 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.
*/
package finalproject;
/**
*
* @author shlok
*/
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import org.knowm.xchart.PieChart;
import org.knowm.xchart.PieChartBuilder;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.Styler.ChartTheme;
public class ExpenditureDistribution {
public XChartPanel getPanel() throws SQLException {
ExpenditureDistribution exampleChart = new ExpenditureDistribution();
PieChart chart = exampleChart.getChart();
XChartPanel panel=new XChartPanel(chart);
return panel;
}
public PieChart getChart() throws SQLException {
// Create Chart
PieChart chart =
new PieChartBuilder()
.width(1366)
.height(748)
.title("Expenditure Distribution In 2017")
.theme(ChartTheme.XChart)
.build();
// Customize Chart
chart.getStyler().setLegendVisible(true);
chart.getStyler().setAnnotationDistance(1.15);
chart.getStyler().setPlotContentSize(.7);
chart.getStyler().setStartAngleInDegrees(90);
chart.getStyler().setToolTipsEnabled(true);
chart.getStyler().setToolTipType(Styler.ToolTipType.yLabels);
ArrayList<Double> a = new ArrayList<Double>();
ArrayList<String> b = new ArrayList<String>();
// Series
int i = 0;
Connection con = DbConnect.getConnection();
Statement statement = con.createStatement();
ResultSet resultset = statement.executeQuery("SELECT * FROM expendituredistribution");
while(resultset.next())
{
a.add(Double.parseDouble(resultset.getString("Amount")));
b.add(resultset.getString("type"));
chart.addSeries(b.get(i),a.get(i));
i++;
}
return chart;
}
}