It's not a secret anymore!*
The moose likes Other Open Source Projects and the fly likes Need to hide borders for a barchart generated with Jfree chart except x and y axis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Need to hide borders for a barchart generated with Jfree chart except x and y axis" Watch "Need to hide borders for a barchart generated with Jfree chart except x and y axis" New topic
Author

Need to hide borders for a barchart generated with Jfree chart except x and y axis

Naresh gangishetty
Greenhorn

Joined: Sep 24, 2008
Posts: 14
Hi,

I have created a bar chart using Jfree chart.I need to hide borders except x and y axis.I have explored through api and didnt find suitable method.

Please let me know if any one knows ASAP.Thanks in advance.Find the code as below.




package com.markettools.portal;

import java.awt.Color;
import java.awt.Dimension;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.ChartFactory;

public class TestBarChart extends ApplicationFrame {

public TestBarChart(String title) {
super(title);
CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}

private CategoryDataset createDataset() {
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
dataset.addValue(2.0, "Colgate", "Taste");
dataset.addValue(3.0, "Closeup", "Taste");
dataset.addValue(2.0, "Pepsodent", "Taste");
dataset.addValue(2.0, "Colgate", "Color");
dataset.addValue(3.0, "Closeup", "Color");
dataset.addValue(2.0, "Pepsodent", "Color");
return dataset;
}

public JFreeChart createChart(CategoryDataset dataset)
{
JFreeChart chart=ChartFactory.createBarChart("Tooth Pastes", "X-axis","Y-axis",dataset, PlotOrientation.HORIZONTAL,true,true,true);
chart.setBorderVisible(false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);


plot.setInsets(new RectangleInsets(0,0,0,0));
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
rangeAxis.setAxisLineVisible(true);
plot.setRangeCrosshairVisible(false);
// chart.getXYPlot().setRangeZeroBaselineVisible(false);
// xyPlot.setRangeZeroBaselineVisible(false);

return chart;

}
/**
*
*/
private static final long serialVersionUID = 1L;

public static void main(String args[])
{
TestBarChart chart1=new TestBarChart("Tooth Pastes");
chart1.pack();
RefineryUtilities.centerFrameOnScreen(chart1);
chart1.setVisible(true);


}

}


Regards,
Naresh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41051
    
  43
Welcome to JavaRanch.

You've already discovered the setBorderVisible method, so I'm not sure which border you're talking about ... ? Can you post images that show what it looks like now, and what you'd like it to look?


Ping & DNS - my free Android networking tools app
Naresh gangishetty
Greenhorn

Joined: Sep 24, 2008
Posts: 14
Bar chart presently displaying in a box even I set setBorderVisible(false);
My intention is to display only x-axis and y-axis leaving other two top,right borders.How ever if I set plot.setInsets(new RectangleInsets(0,0,0,0)) it is hiding right side border.I need a way to hide top also.

I think you got it?
Naresh gangishetty
Greenhorn

Joined: Sep 24, 2008
Posts: 14
I understood that setBordersVisible(false) is for chart level.I want to hide right,top borders of plot.
Naresh gangishetty
Greenhorn

Joined: Sep 24, 2008
Posts: 14
Hi everyone,

I got information what I was looking for at that time.Just want to update so that it could be helpful to any one.Please refer foolwoing conversation.

http://www.jfree.org/phpBB2/viewtopic.php?p=72746#72746

Thanks,
Naresh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to hide borders for a barchart generated with Jfree chart except x and y axis
 
Similar Threads
Displaying scalable vector graphics on ibm aix
Problem in displaying waterfall chart with -ve values
Need to pass information from MS Access database to another program
Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart
problem in displaying text in item label in JFreeChart