Updates from August, 2007 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 4:33 pm on August 6, 2007 Permalink |  

    An Introduction to JavaFX Script – http://java.sun.com/ 

    The JavaFX Script programming language (hereinafter referred to as JavaFX) is a declarative, statically typed scripting language from Sun Microsystems, Inc. As mentioned on the Open JavaFX (OpenJFX) web site, JavaFX technology has a wealth of features, including the ability to make direct calls to Java technology APIs. Because JavaFX Script is statically typed, it also has the same code structuring, reuse, and encapsulation features — such as packages, classes, inheritance, and separate compilation and deployment units — that make it possible for your to create and maintain very large programs using Java technology.

    Find this article: http://java.sun.com/developer/technicalArticles/scripting/javafxpart1/
    Source: http://java.sun.com/

  • Subinkrishna Gopi 12:13 pm on August 6, 2007 Permalink |

    Creating Pie Charts using JFreeChart with custom colors 

    I have attached a sample code snippet for creating a Pie Chart using JFreeChart with custom colors. There is a PieReneder (a static inner class) which can be used to achieve the same. The PieRenderer takes an array of java.awt.Color in its constructor.

    package subin.rnd.chart;
    import java.awt.Color; 
    import java.io.File; 
    import java.util.List;
    import org.jfree.chart.ChartFactory; 
    import org.jfree.chart.ChartUtilities; 
    import org.jfree.chart.JFreeChart; 
    import org.jfree.chart.plot.PiePlot; 
    import org.jfree.data.general.DefaultPieDataset;
    public class PieChartWithCustomColours 
        public static void main(String[] args) 
            DefaultPieDataset dataset = new DefaultPieDataset(); 
            JFreeChart chart; 
            // Defining the dataset 
            dataset.setValue("Windows", 60); 
            dataset.setValue("Linux", 20); 
            dataset.setValue("Mac", 10); 
            dataset.setValue("Unix", 5); 
            dataset.setValue("DOS", 5); 
            chart = ChartFactory.createPieChart( 
                    "OS Chart", dataset, false, false, false); 
            PiePlot plot = (PiePlot)chart.getPlot(); 
            // Specify the colors here 
            Color[] colors = {Color.blue, Color.yellow, Color.green}; 
            PieRenderer renderer = new PieRenderer(colors); 
            renderer.setColor(plot, dataset); 
                // This will create a PNG image 
                ChartUtilities.saveChartAsPNG(new File("chart.png"), chart, 400, 
            catch (Exception e) 
                System.out.println("Exception while creating the chart"); 
         * A simple renderer for setting custom colors 
         * for a pie chart. 
        public static class PieRenderer 
            private Color[] color; 
            public PieRenderer(Color[] color) 
                this.color = color; 
            public void setColor(PiePlot plot, DefaultPieDataset dataset) 
                List <Comparable> keys = dataset.getKeys(); 
                int aInt; 
                for (int i = 0; i < keys.size(); i++) 
                    aInt = i % this.color.length; 
                    plot.setSectionPaint(keys.get(i), this.color[aInt]); 

    Sample Output

    Pie Chart With Custom Colors (JFreeChart)

    Here the colors are repeating, right? Its b’ coz there is only three entries in the input color array to the PieRenderer.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc