-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathjfreeChart1.scala
More file actions
32 lines (25 loc) · 898 Bytes
/
Copy pathjfreeChart1.scala
File metadata and controls
32 lines (25 loc) · 898 Bytes
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
import org.jfree.chart.{ChartPanel, ChartFactory, JFreeChart, ChartUtilities}
import org.jfree.data.general.DefaultPieDataset
val dataset = new DefaultPieDataset()
dataset.setValue("A", 75)
dataset.setValue("B", 10)
dataset.setValue("C", 10)
dataset.setValue("D", 5)
val chart = ChartFactory.createPieChart(
"Sample Pie Chart", // Title
dataset, // Dataset
true, // Show legend
true, // Tooltips on
false
)
// Save chart to a png file
//---------------------------
ChartUtilities.saveChartAsPNG(new java.io.File("mychart.png"), chart, 500, 500)
// Show Chart in a Java Swing Frame
//--------------------------------------
val frame = new javax.swing.JFrame()
frame.add(new ChartPanel(chart))
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE)
frame.setSize(693, 513)
frame.setTitle("Sample Pie Chart")
frame.setVisible(true)