File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart" Watch "Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart" New topic

Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart

San Nan

Joined: Jul 01, 2005
Posts: 22
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.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) {


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


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();
org.jfree.chart.renderer.category.BarRenderer barrenderer =

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

// displaying Value on Each Bar

return chart;


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

final First2 demo = new First2("Stacked Bar Chart");



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
I agree. Here's the link:
subject: Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart
jQuery in Action, 3rd edition