*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart

San Nan
Greenhorn

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.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
 
 
subject: Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart
 
Similar Threads
Displaying scalable vector graphics on ibm aix
problem in displaying text in item label in JFreeChart
Need to hide borders for a barchart generated with Jfree chart except x and y axis
servlet chart generate problem
Generate RADAR chart in jsp