/** * Constructor. */ public BarPlot(double[] data) { super(Color.BLUE); this.data = new double[data.length][2]; for (int i = 0; i < data.length; i++) { this.data[i][0] = i + 0.5; this.data[i][1] = data[i]; } init(); }
/** * Create a plot canvas with the bar plot of given data. * @param data a vector of which values will determine the heights of bars. * @param labels the labels for each bar. */ public static PlotCanvas plot(double[] data, String[] labels) { return plot(null, data, labels); }
/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a n x 2 matrix of which data[][0] determine the location of * bars and data[][1] determine the heights of bars. data[][0] will also be * used as the labels. For best view, data[][0] should be monotonic. */ public static PlotCanvas plot(String id, double[]... data) { if (data[0].length != 2) { throw new IllegalArgumentException("Dataset is not 2-dimensional."); } double[] lowerBound = Math.colMin(data); double[] upperBound = Math.colMax(data); PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); canvas.getAxis(0).setGridVisible(false); BarPlot plot = new BarPlot(data); plot.setID(id); canvas.add(plot); return canvas; } }
@Override public void paint(Graphics g) { Color c = g.getColor(); g.setColor(Color.BLACK); for (int i = 0; i < data.length; i++) { g.drawLine(leftBottom[i], leftTop[i]); g.drawLine(leftTop[i], rightTop[i]); g.drawLine(rightTop[i], rightBottom[i]); g.drawLine(rightBottom[i], leftBottom[i]); } g.setColor(getColor()); for (int i = 0; i < data.length; i++) { g.fillPolygon(0.2f, leftBottom[i], leftTop[i], rightTop[i], rightBottom[i]); } g.setColor(c); }
/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a vector of which values will determine the heights of bars. */ public static PlotCanvas plot(String id, double[] data) { double[] lowerBound = {0, Math.min(data)}; double[] upperBound = {data.length, Math.max(data)}; PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); BarPlot plot = new BarPlot(data); plot.setID(id); canvas.add(plot); canvas.getAxis(0).setGridVisible(false); canvas.getAxis(0).setLabelVisible(false); return canvas; }
/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a vector of which values will determine the heights of bars. * @param labels the labels for each bar. */ public static PlotCanvas plot(String id, double[] data, String[] labels) { if (data.length != labels.length) { throw new IllegalArgumentException("Data size and label size don't match."); } double[] lowerBound = {0, Math.min(data)}; double[] upperBound = {data.length, Math.max(data)}; PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); BarPlot plot = new BarPlot(labels, data); plot.setID(id); canvas.add(plot); double[] locations = new double[labels.length]; for (int i = 0; i < labels.length; i++) { locations[i] = i + 0.5; } canvas.getAxis(0).addLabel(labels, locations); canvas.getAxis(0).setGridVisible(false); return canvas; }
/** * Constructor. */ public BarPlot(int[] data) { super(Color.BLUE); this.data = new double[data.length][2]; for (int i = 0; i < data.length; i++) { this.data[i][0] = i + 0.5; this.data[i][1] = data[i]; } init(); }
/** * Create a plot canvas with the bar plot of given data. * @param data a vector of which values will determine the heights of bars. */ public static PlotCanvas plot(double[] data) { return plot(null, data); }
/** * Constructor. */ public BarPlot(double[][] data) { super(Color.BLUE); if (data[0].length != 2) { throw new IllegalArgumentException("Dataset is not 2-dimensional."); } this.data = data; init(); }
/** * Create a plot canvas with the bar plot of given data. * @param data a n x 2 matrix of which data[][0] determine the location of * bars and data[][1] determine the heights of bars. data[][0] will also be * used as the labels. For best view, data[][0] should be monotonic. */ public static PlotCanvas plot(double[]... data) { return plot(null, data); }
/** * Constructor. */ public BarPlot(int[][] data) { super(Color.BLUE); if (data[0].length != 2) { throw new IllegalArgumentException("Invalid data dimension: " + data[0].length); } this.data = new double[data.length][2]; for (int i = 0; i < data.length; i++) { this.data[i][0] = data[i][0]; this.data[i][1] = data[i][1]; } init(); }
/** * Constructor. */ public BarPlot(String[] description, double[] data) { super(Color.BLUE); if (data.length != description.length) { throw new IllegalArgumentException("Data size and label size don't match."); } this.description = description; this.data = new double[data.length][2]; for (int i = 0; i < data.length; i++) { this.data[i][0] = i + 0.5; this.data[i][1] = data[i]; } init(); }