BarChart Tick and axis color slightly lighter than set

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ZiziTheFirst
Posts: 2
Joined: Thu Aug 11, 2016 11:21 am
antibot: No, of course not.

BarChart Tick and axis color slightly lighter than set

Post by ZiziTheFirst » Thu Aug 11, 2016 11:58 am

I have noticed when trying to change the color of axes and their tick marks that the resulting color is slightly lighter thant set. Why is that - is that on purpose, result of some interpolation, alpha transparency or smoothing?

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());
Image

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)

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: BarChart Tick and axis color slightly lighter than set

Post by paradoxoff » Thu Aug 11, 2016 8:30 pm

Do you observe the same behaviour with a thicker stroke?
If not, then it may come from the newly integrated RenderingHints.KEY_STROKE_CONTROL.

ZiziTheFirst
Posts: 2
Joined: Thu Aug 11, 2016 11:21 am
antibot: No, of course not.

Re: BarChart Tick and axis color slightly lighter than set

Post by ZiziTheFirst » Fri Aug 12, 2016 11:59 am

paradoxoff wrote:Do you observe the same behaviour with a thicker stroke?
No, with thicker stroke it behaves as expected. The behavior is caused by both axisLineStroke and tickMarkStroke having a stroke of width 0.5 by default.

Code: Select all

Stroke tickMarkStroke = valueAxis.getTickMarkStroke();
Stroke axisLineStroke = valueAxis.getAxisLineStroke();

BasicStroke
cap                   2	
dash	            null	
dash_phase          0.0	
join                  0	
miterlimit         10.0	
width               0.5	
When I override it with Stroke solid from previous code it starts to look as expected.

Code: Select all

valueAxis.setAxisLineStroke(solid);
valueAxis.setTickMarkStroke(solid);
domainAxis.setAxisLineStroke(solid);
domainAxis.setTickMarkStroke(solid);
Image

Excessively thick stroke (width=5) works also fine.

Code: Select all

Stroke solid = new BasicStroke(5);
Image

It just did not occur to me at first that (and why) default widths would be in fractions. Thanks for the tip!

Locked