Dev
Dev

Reputation: 51

Customized Stacked area chart in JFreeChart

I am new to the JFreeChart and i have created stacked area chart. My problem is to remove GridLines in a chart. I searched a whole day regarding this issue. I didn't found proper solution. Please help me to sort it out.

final JFreeChart chart = ChartFactory.createStackedAreaChart(
            "", //Chart title 
            "", // domain axis label
            "Millions", // range axis label 
            otherdataset, // data 
            PlotOrientation.VERTICAL, // orientation 
            true, // include legend 
            false, 
            true);

LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.LEFT);
legend.setFrame(BlockBorder.NONE);

chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = (CategoryPlot) chart.getPlot();

plot.getRenderer().setSeriesPaint(0, new java.awt.Color(0, 0, 128));
plot.getRenderer().setSeriesPaint(1, new java.awt.Color(192, 80, 77));
plot.getRenderer().setSeriesPaint(2, new java.awt.Color(155, 187, 83));
plot.getRenderer().setSeriesPaint(3, new java.awt.Color(79, 129, 189));
plot.getRenderer().setSeriesPaint(4, new java.awt.Color(75, 0, 130));
plot.getRenderer().setSeriesPaint(5, new java.awt.Color(233, 125, 35));

plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinesVisible(false);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinesVisible(false);
plot.setRangeGridlinePaint(Color.white);
plot.setNoDataMessage("No data found");

int width = 1000; // Width of the image
int height = 200; // Height of the image
File stackedAreaChart = new File("D:/graph.jpeg");

ChartUtilities.saveChartAsJPEG(stackedAreaChart, chart, width, height);

Current Output: Have to remove grid lines in current graph

Required Output: enter image description here

Upvotes: 2

Views: 527

Answers (1)

Dev
Dev

Reputation: 51

Finally i resolved the issue by adding below statement.

chart.setAntiAlias(false);

Upvotes: 1

Related Questions