source: src/main/java/genius/gui/chart/UtilityPlot.java@ 155

Last change on this file since 155 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 2.5 KB
Line 
1package genius.gui.chart;
2
3import org.jfree.chart.*;
4import org.jfree.chart.plot.*;
5import org.jfree.chart.renderer.xy.XYItemRenderer;
6import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
7import org.jfree.chart.axis.*;
8import org.jfree.data.xy.*;
9
10import javax.swing.*;
11
12public class UtilityPlot extends JPanel{
13
14 private static final long serialVersionUID = 8533262082855615666L;
15 private DefaultXYDataset dataset = new DefaultXYDataset();
16 private String xAxisLabel = "round";
17 private String yAxisLabel = "my utility of bid";
18 private ChartPanel panel;
19 JFreeChart chart;
20
21 //the constructor for the utilities per round graph:
22 public UtilityPlot(double [][] myBidSeries, double [][] oppBidSeries){
23 //add the series to the dataset:
24 dataset.addSeries("my bids",myBidSeries);
25 dataset.addSeries("opponent's bids",oppBidSeries);
26 init();
27 }
28
29 private void init(){
30 final XYItemRenderer renderer = new XYLineAndShapeRenderer();
31 NumberAxis domainAxis = new NumberAxis(xAxisLabel);
32 ValueAxis rangeAxis = new NumberAxis(yAxisLabel);
33 XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
34 chart = new JFreeChart("Utilities per round", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
35
36 /* just a simple line chart:
37 * chart = ChartFactory.createXYLineChart(
38 headline,
39 xAxisLabel,//xAxisLabel
40 yAxisLabel,//yAxisLabel
41 dataset, // the data to be displayed
42 PlotOrientation.VERTICAL, //if set to horizontal x- and y-axis are switched
43 true, // legend? yes we want a legend
44 false, // tooltips?
45 false // URLs?
46 );*/
47
48 // This is how you change the values on the x-axis to only integer values
49 // the x-axis is called domainAxis, the y-axis rangeAxis
50 domainAxis = (NumberAxis) plot.getDomainAxis();
51 domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
52
53 rangeAxis = (NumberAxis) plot.getRangeAxis();
54 //if it is important that the axis' values start with 0:
55 //rangeAxis.setAutoRangeIncludesZero(true);
56
57 //like this you can set the range of the axis manually
58 //(since we know that the utilities are always between 0 and 1 it makes sense.)
59 //I set the range to 1.1 because it gives a little more space at the top,
60 //since we could have utilities that are 1.0 it will look a bit better
61 rangeAxis.setRange(0,1.1);
62
63 }
64
65 public ChartPanel getChartPanel(){
66 return panel;
67 }
68
69 public JFreeChart getChart(){
70 return chart;
71 }
72}
73
74
Note: See TracBrowser for help on using the repository browser.