This is most apparent when I remove the gap between the plot and the axis so that the lines touch - setting all lines' colors to Color.BLACK results in an inconsistent look with the rangeGridlinePaint black #000000 as expected, but axes rendered with not-exactly-but-still-black-enough color #404040 and tick marks at visibly lighter gray #808080.
Can I tweak something so that all the colors are black, or is this a bug or an expected result of something out of my or your control?
Code: Select all
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(8000, "Line 1", "Value 1");
dataset.addValue(6000, "Line 1", "Value 2");
final JFreeChart barChart = ChartFactory.createBarChart(
null,
null, null,
dataset, PlotOrientation.VERTICAL,
false, false, false);
Color colorOverride = Color.BLACK;
Stroke solid = new BasicStroke(1);
CategoryPlot plot = barChart.getCategoryPlot();
plot.setRangeGridlineStroke(solid);
StandardChartTheme theme = StandardChartTheme.createJFreeTheme();
theme.setPlotBackgroundPaint(Color.WHITE);
theme.setRangeGridlinePaint(colorOverride);
theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); // disables the gap between graph and axes
theme.apply(barChart);
ValueAxis valueAxis = plot.getRangeAxis();
valueAxis.setTickLabelsVisible(false);
valueAxis.setTickMarkOutsideLength(10); // longer tick lines
valueAxis.setAxisLinePaint(colorOverride); // X and Y axis line color
valueAxis.setTickMarkPaint(colorOverride); // tiny dashes sticking out every Nth value on Y axis
CategoryAxis domainAxis = plot.getDomainAxis()
domainAxis.setAxisLinePaint(colorOverride);
File file = File.createTempFile("chart", ".png");
ChartUtilities.saveChartAsPNG(file, barChart, 500, 300);
System.out.println("Saved chart to file " + file.getAbsolutePath());
My configuration is as follows:
- JFreeChart 1.0.19
- java version "1.8.0_101", Java(TM) SE Runtime Environment (build 1.8.0_101-b13), Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)