Ejemplo n.º 1
0
 public static void drawAndSaveChartAsImageFile(JAwesomeChart ac, String filePath) {
   BufferedImage bi =
       new BufferedImage(ac.getWidth(), ac.getHeight(), BufferedImage.TYPE_INT_ARGB);
   long t1 = System.currentTimeMillis();
   double i;
   int iterations = 1;
   for (i = 0; i < iterations; i += 1) {
     ac.draw(bi.getGraphics());
   }
   long t2 = System.currentTimeMillis();
   System.out.println(
       ac.getRenderer().getHumanReadableName() + " chart - mean time: " + ((t2 - t1) / i) + " ms");
   try {
     File f = new File(filePath);
     if (f.exists()) {
       f.delete();
     }
     f.mkdirs();
     ImageIO.write(bi, "png", f);
   } catch (IOException ioe) {
     System.err.println(ioe.getMessage());
   }
 }
Ejemplo n.º 2
0
  public static void main(String[] args) {

    JAwesomeChart ac = new JAwesomeChart(960, 450);
    ac.setTitle("Αποτελέσματα Βουλευτικών Εκλογών 17/06/2012");
    ac.addSeries("ΝΔ", new double[] {29.66}, Color.decode("0x003A65"));
    ac.addSeries("ΣΥ.ΡΙΖ.Α", new double[] {26.89}, Color.decode("0xBC1C93"));
    ac.addSeries("ΠΑ.ΣΟ.Κ", new double[] {12.28}, Color.decode("0x146D36"));
    ac.addSeries("ΑΝΕΞ.ΕΛΛ", new double[] {7.51}, Color.decode("0x8FB7D5"));
    ac.addSeries("ΧΡ.ΑΥΓΗ", new double[] {6.92}, Color.decode("0x333333"));
    ac.addSeries("ΔΗΜ.ΑΡ", new double[] {6.26}, Color.decode("0xFF7E00"));
    ac.addSeries("Κ.Κ.Ε", new double[] {4.5}, Color.decode("0xFF0012"));
    ac.addSeries("ΔΗ.ΞΑ", new double[] {1.59}, Color.decode("0xBE71FF"));
    ac.addSeries("ΛΑ.Ο.Σ", new double[] {1.58}, Color.decode("0x70A2C9"));
    ac.addSeries("ΟΙΚ.ΠΡΑ", new double[] {0.88}, Color.decode("0x819862"));
    ac.addSeries("ΛΟΙΠΑ", new double[] {1.93}, Color.decode("0xAAAAAA"));

    ChartRenderer renderer2 = new ColumnChartRenderer();
    ac.setRenderer(renderer2);
    drawAndSaveChartAsImageFile(
        ac, "/home/cyberpython/Desktop/greek-legislative-elections-2012-06-17-bars.png");

    Utilities.xdgOpenFile(
        new File("/home/cyberpython/Desktop/greek-legislative-elections-2012-06-17-bars.png"));
  }