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

    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.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)   
            CategoryDataset categorydataset = createDataset();   
            JFreeChart jfreechart = createChart(categorydataset);   
            ChartPanel chartpanel = new ChartPanel(jfreechart);   
            chartpanel.setPreferredSize(new Dimension(500, 270));   
        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.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());   
            extendedstackedbarrenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());   
            ValueAxis valueaxis = categoryplot.getRangeAxis();   
            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");   
    Last edited by Norm; 03-20-2012 at 04: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, 04:11 PM
  2. modify XML file
    By Fireholder in forum Advanced Java
    Replies: 1
    Last Post: 04-19-2011, 09:06 AM
  3. How can I Modify set method?
    By Ms.Ranjan in forum New To Java
    Replies: 5
    Last Post: 04-21-2009, 10:16 PM
  4. Demo bar chart and pie chart
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:22 PM
  5. Modify A* Algorithm
    By prakharbirla in forum Advanced Java
    Replies: 1
    Last Post: 02-13-2008, 06: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