- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot.java
More file actions
Latest commit
50 lines (42 loc) · 1.47 KB
/
Copy pathPlot.java
File metadata and controls
50 lines (42 loc) · 1.47 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
packageFileManagement;
importjava.io.File;
importjava.io.IOException;
importjava.util.Map;
importorg.jfree.chart.ChartFactory;
importorg.jfree.chart.ChartUtilities;
importorg.jfree.chart.JFreeChart;
importorg.jfree.data.general.DefaultPieDataset;
publicclassPlot {
/**
* Plots the pie chart.
*
* @param Map<String, Double>, file path to save the chart and name of the chart.
*
* @return N/A
*
*/
publicstaticvoidplot_pie_chart(Map<String, Double> data, StringfilePath, StringchartTitle)
{
DefaultPieDatasetdataset = newDefaultPieDataset( );
for(Map.Entrym:data.entrySet()){
dataset.setValue((String) m.getKey(), newDouble( (double) m.getValue() ) );
}
JFreeChartchart = ChartFactory.createPieChart(
chartTitle, // chart title
dataset, // data
true, // include legend
true,
false);
intwidth = 1500; /* Width of the image */
intheight = 1500; /* Height of the image */
FilepieChart = newFile(filePath);
try {
ChartUtilities.saveChartAsJPEG( pieChart , chart , width , height );
System.out.println(filePath +" graph generated.");
System.out.println();
} catch (IOExceptione) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}