Updates from July, 2007 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 3:04 pm on July 4, 2007 Permalink |  

    Java 7: Dolphin 

    Sun is releasing weekly early access snapshots of the complete source, binaries and documentation for JDK 7. These raw snapshot releases let you review and contribute to the Java SE platform as it is being developed.

    Some possible language changes being considered for Dolphin include:

    • property support (for getFoo()/setFoo() pattern)
    • method references (a quick way to write an event notification pattern)
    • block closures (collection of statements within a statement)
    • native XML support

    For more information:
    Latest JDK 7 binary snapshots
    Latest JDK 7 source snapshots
    Latest JDK 7 Java Docs
    Summary of changes in JDK 7

    Source: https://jdk7.dev.java.net/

    Advertisements
     
  • Subinkrishna Gopi 1:19 pm on July 4, 2007 Permalink |
    Tags:   

    Creating BarCharts with custom colours using JFreeChart 

    This can be achieved by extending the BarRenderer. BarRenderer is responsible for all kind of UI related things like setting the font, setting the colors, setting the alignment etc etc. Rather we can say everything. The same can be achieved by extending corresponding renderer.

    Here the getItemPaint(row, col) has been overridden to achieve the custom colors.

    CustomRenderer:

    import org.jfree.chart.renderer.category.BarRenderer; 
    import java.awt.Color; 
    import java.awt.Paint;
    class CustomRenderer extends BarRenderer 
    { 
     private Paint[] colors;
     public CustomRenderer() 
     { 
        this.colors = new Paint[] {Color.red, Color.blue, Color.green, 
          Color.yellow, Color.orange, Color.cyan, 
          Color.magenta, Color.blue}; 
     }
     public Paint getItemPaint(final int row, final int column) 
     { 
        // returns color for each column 
        return (this.colors[column % this.colors.length]); 
     } 
    }
     

    Using custom renderer with the CategoryPlot:

    final JFreeChart chart = ChartFactory.createBarChart( 
       "chart title", 
       "x axis label", 
       "y axis label ", 
       dataset, 
       PlotOrientation.VERTICAL, 
       false,                 
       true, 
       false 
    );
    chart.setBackgroundPaint(Color.lightGray);
    // get a reference to the plot for further customisation... 
    final CategoryPlot plot = chart.getCategoryPlot(); 
    CategoryItemRenderer renderer = new CustomRenderer(); 
    plot.setRenderer(renderer);
     

    Other useful links:
    Creating a 3D BarChart using JFreeChart
    Creating Time Series charts using JFreeChart
    Creating Pie Chart using JFreeChart (Using plot)
    Creating Pie Chart using JFreeChart

     
  • Subinkrishna Gopi 5:41 am on July 4, 2007 Permalink |
    Tags:   

    Creating a 3D BarChart using JFreeChart 

    The given code snippet can create a 3D Bar Chart. The given Bar Chart compares 2 aspects of each customer. The generated chart will have two bars for each customer for both Profit1 and Profit 2 (see the dataset).

    Profit 1 can can be total annual profit and Profit 2 can be profit for a particular period like monthly or weekly profit. Please find the sample image created using this code.

    DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 
    dataset.setValue(6, "Profit1", "Jane"); 
    dataset.setValue(3, "Profit2", "Jane"); 
    dataset.setValue(7, "Profit1", "Tom"); 
    dataset.setValue(10, "Profit2", "Tom"); 
    dataset.setValue(8, "Profit1", "Jill"); 
    dataset.setValue(8, "Profit2", "Jill"); 
    dataset.setValue(5, "Profit1", "John"); 
    dataset.setValue(6, "Profit2", "John"); 
    dataset.setValue(12, "Profit1", "Fred"); 
    dataset.setValue(5, "Profit2", "Fred");
    // Profit1, Profit2 represent the row keys 
    // Jane, Tom, Jill, etc. represent the column keys
    JFreeChart chart = ChartFactory.createBarChart3D( 
       "Comparison between Salesman",  // Chart name 
       "Salesman",                     // X axis label 
       "Value ($)",                    // Y axis value 
       dataset,                        // data set 
       PlotOrientation.VERTICAL, 
       true, true, false);
    // Creating a JPEG image 
    try 
    { 
       ChartUtilities.saveChartAsJPEG(new File("myChart.jpg"), chart, 500, 300); 
    } 
    catch (IOException e) 
    { 
       System.err.println("Problem occurred creating chart."); 
    } 
    

    Image generated:

    3d BarChart Generated using JFreeChart

    Other useful links:
    Creating Time Series charts using JFreeChart
    Creating Pie Chart using JFreeChart (Using plot)
    Creating Pie Chart using JFreeChart

     
    • joensson 10:58 am on July 12, 2007 Permalink

      What version of JFreeChart are you using?

      I’m complete new at JFreeChart and have found a ton of examples using the old interface. However I have to use 1.0.6 and the signature of DefaultCategoryDataset setValue is double, Comparable, Comparable – how would you create the chart using 1.0.6?

    • Subin 11:51 am on July 12, 2007 Permalink

      Hi joensson,

      Even I am using JFreeChart 1.0.6. Actually Comaprable is an interface which contains a method specification “public int compareTo(Object o)“. I hope you know what it means. It’s used to compare two different objects.

      String is a class which implements Comparable. We can use any object which is implementing Comparable interface as an argument to the “setValue(double, comparable, comparable);

      I hope this can fix your problem.
      Thank you for visiting my Blog & for the very first comment.

      Subin

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel