This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Naresh gangishetty
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood that setBordersVisible(false) is for chart level.I want to hide right,top borders of plot.
 
Naresh gangishetty
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!