Results 1 to 1 of 1
  1. #1
    ginger0001 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Default How to modify stacked bar chart?(JFreeChart)

    The output of this graph is stacked bar chart but it show number in stack and on the top most of the stack.
    1. I want to keep the number in each stack but I want to delete the number at the top most
    2. The top most position, I want to put other number that are in form of int not the total number of this stack
    How can I modify this code, I am very new to java.

    Thank you
    Java Code:
    import java.awt.Dimension;   
    import javax.swing.JPanel;   
    import org.jfree.chart.*;   
    import org.jfree.chart.axis.NumberAxis;   
    import org.jfree.chart.axis.ValueAxis;   
    import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;   
    import org.jfree.chart.labels.StandardCategoryToolTipGenerator;   
    import org.jfree.chart.plot.CategoryPlot;   
    import org.jfree.chart.plot.PlotOrientation;   
    import org.jfree.data.category.CategoryDataset;   
    import org.jfree.data.category.DefaultCategoryDataset;   
    import org.jfree.ui.ApplicationFrame;   
    import org.jfree.ui.RefineryUtilities;   
    
    import demo.ExtendedStackedBarRenderer;
       
    // Referenced classes of package demo:   
    //            ExtendedStackedBarRenderer   
       
    public class StackDemo extends ApplicationFrame   
    {   
       
        /**  
         *   
         */   
        private static final long serialVersionUID = 1L;   
       
        public StackDemo(String s)   
        {   
            super(s);   
            CategoryDataset categorydataset = createDataset();   
            JFreeChart jfreechart = createChart(categorydataset);   
            ChartPanel chartpanel = new ChartPanel(jfreechart);   
            chartpanel.setPreferredSize(new Dimension(500, 270));   
            setContentPane(chartpanel);   
        }   
       
        private static CategoryDataset createDataset()   
        {   
            DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();   
            defaultcategorydataset.addValue(10, "Vacant", "Jan");   
            defaultcategorydataset.addValue(12, "Vacant", "Feb");   
            defaultcategorydataset.addValue(13, "Vacant", "Mar");   
            defaultcategorydataset.addValue(4, "Discount", "Jan");   
            defaultcategorydataset.addValue(3, "Discount", "Feb");   
            defaultcategorydataset.addValue(2, "Discount", "Mar");   
            defaultcategorydataset.addValue(2, "Regular", "Jan");   
            defaultcategorydataset.addValue(3, "Regular", "Feb");   
            defaultcategorydataset.addValue(2, "Regular", "Mar");   
             
            return defaultcategorydataset;   
        }   
       
        private static JFreeChart createChart(CategoryDataset categorydataset)   
        {   
            JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 3", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, false, false);   
            CategoryPlot categoryplot = jfreechart.getCategoryPlot();   
            ExtendedStackedBarRenderer extendedstackedbarrenderer = new ExtendedStackedBarRenderer();   
            extendedstackedbarrenderer.setItemLabelsVisible(true);   
            extendedstackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());   
            extendedstackedbarrenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());   
            categoryplot.setRenderer(extendedstackedbarrenderer);   
            ValueAxis valueaxis = categoryplot.getRangeAxis();   
            valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());   
            valueaxis.setLowerMargin(0.14999999999999999D);   
            valueaxis.setUpperMargin(0.14999999999999999D);   
            return jfreechart;   
        }   
       
        public static JPanel createDemoPanel()   
        {   
            JFreeChart jfreechart = createChart(createDataset());   
            return new ChartPanel(jfreechart);   
        }   
       
        public static void main(String args[])   
        {   
            StackDemo stackedbarchartdemo3 = new StackDemo("Stacked Bar Chart Demo 3");   
            stackedbarchartdemo3.pack();   
            RefineryUtilities.centerFrameOnScreen(stackedbarchartdemo3);   
            stackedbarchartdemo3.setVisible(true);   
        }   
    }
    Last edited by Norm; 03-20-2012 at 05:38 PM. Reason: added code tags

Similar Threads

  1. Jfreechart api- bar chart
    By saneel4u in forum Advanced Java
    Replies: 5
    Last Post: 07-06-2011, 05:11 PM
  2. modify XML file
    By Fireholder in forum Advanced Java
    Replies: 1
    Last Post: 04-19-2011, 10:06 AM
  3. How can I Modify set method?
    By Ms.Ranjan in forum New To Java
    Replies: 5
    Last Post: 04-21-2009, 11:16 PM
  4. Demo bar chart and pie chart
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-24-2008, 12:22 AM
  5. Modify A* Algorithm
    By prakharbirla in forum Advanced Java
    Replies: 1
    Last Post: 02-13-2008, 07:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •