-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoOfVolumes.java
85 lines (85 loc) · 3.11 KB
/
NoOfVolumes.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* 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;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.demo.charts.ExampleChart;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.Styler.ChartTheme;
import static org.knowm.xchart.style.Styler.LegendPosition.OutsideS;
/**
*
* @author shlok
*/
public class NoOfVolumes implements ExampleChart<CategoryChart> {
public XChartPanel getPanel() throws IOException {
ExampleChart<CategoryChart> exampleChart = new NoOfVolumes();
CategoryChart chart = exampleChart.getChart();
XChartPanel panel=new XChartPanel(chart);
return panel;
}
@Override
public CategoryChart getChart() {
// Create Chart
Connection con = DbConnect.getConnection();
CategoryChart chart = new CategoryChartBuilder().width(1366).height(748)
.title("BRANCH WISE DISTRIBUTION")
.xAxisTitle("BRANCH")
.yAxisTitle("DISTRIBUTION")
.theme(ChartTheme.Matlab).build();
// Customize Chart
chart.getStyler().setPlotGridLinesVisible(false);
chart.getStyler().setLegendPosition(OutsideS);
chart.getStyler().setToolTipsEnabled(true);
chart.getStyler().setToolTipType(Styler.ToolTipType.yLabels);
// Series
List<String> xData = new ArrayList<>();
List<Integer> yData = new ArrayList<>();
try {
Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM noofvolumes");
int i = 0;
while (resultSet.next())
{
xData.add(i,resultSet.getString("BRANCH"));
yData.add(i,Integer.parseInt(resultSet.getString("VOLUMES")));
i++;
}
}
catch (NumberFormatException | SQLException e)
{
System.out.println(e);
}
chart.addSeries("NUMBER OF VOLUMES",xData,yData);
List<String> xData1 = new ArrayList<>();
List<Integer> yData1 = new ArrayList<>();
try {
Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM noofvolumes");
int i = 0;
while (resultSet.next())
{
xData1.add(i,resultSet.getString("BRANCH"));
yData1.add(i,Integer.parseInt(resultSet.getString("TITLES")));
i++;
}
}
catch (NumberFormatException | SQLException e)
{
System.out.println(e);
}
chart.addSeries("NUMBER OF TITLES",xData1,yData1);
return chart;
}
}