Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

=====================================================
I have created a StackedBar chart using JFreeChart. it working fine. the code is :->
======================================================

import java.awt.Dimension;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.TextAnchor;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.axis.*;
public class First2 extends ApplicationFrame
{
public First2(final String title) {

super(title);

final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);

}


private CategoryDataset createDataset() {
// row keys...
final String series1 = "S1";
final String series2 = "S2";
final String series3 = "S3";

// column keys...
final String category1 = "January";
final String category2 = "February";
final String category3 = "March";

// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(1.0, series1, category1);
dataset.addValue(4.0, series1, category2);
dataset.addValue(3.0, series1, category3);

// For Negative Value
// Put - (Minus) symbol before the value

dataset.addValue(5.0, series2, category1);
dataset.addValue(7.0, series2, category2);
dataset.addValue(6.0, series2, category3);

dataset.addValue(4.0, series3, category1);
dataset.addValue(3.0, series3, category2);
dataset.addValue(2.0, series3, category3);

return dataset;
}



private JFreeChart createChart(final CategoryDataset dataset)
{
// create the chart...
final JFreeChart chart = ChartFactory.createStackedBarChart3D
(
"Stacked Bar Chart", // chart title
"M o n t h s", // domain axis label
"Value in $", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);





org.jfree.chart.plot.CategoryPlot categoryplot = chart.getCategoryPlot();
categoryplot.setBackgroundPaint(java.awt.Color.lightGray);
categoryplot.setRangeGridlinePaint(java.awt.Color.white);
categoryplot.setRangeGridlinesVisible(true);
org.jfree.chart.renderer.category.BarRenderer barrenderer =
(org.jfree.chart.renderer.category.BarRenderer)categoryplot.getRenderer();


java.text.DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00");
decimalformat1.setNegativePrefix("(");
decimalformat1.setNegativeSuffix(")");
barrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));

// displaying Value on Each Bar
barrenderer.setItemLabelsVisible(true);


return chart;

}

public static void main(final String[] args) {

final First2 demo = new First2("Stacked Bar Chart");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);


}
}

===============================================================

Now i want to display a Dollar Symbol at Vertical Bar For Displying the Values in Dollar..... Can ANyone Please Help me for the Same..


Thanks & Regards


San Nan
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!