Code: Select all
int alpha = 50;
int rowCount = jFreeChart.getCategoryPlot().getDataset().getRowCount();
if(rowCount > 1)
alpha = alpha * 1 / rowCount);
for(Object object: jFreeChart.getCategoryPlot().getDataset().getColumnKeys())
{
Comparable comparable = (Comparable) object;
CategoryMarker categoryMarker = new CategoryMarker(comparable);
categoryMarker.setPaint(new Color(Color.LIGHT_GRAY.getRed(), Color.LIGHT_GRAY.getGreen(), Color.LIGHT_GRAY.getBlue(), alpha));
jFreeChart.getCategoryPlot().addDomainMarker(categoryMarker, Layer.BACKGROUND);
}
Just passing this along. I’m retired and playing with this so it’s not an issue for me. I do this to keep my mind busy.
One final thing – David, you’ve created a wonderful tool for transforming machine data to human information that creates human knowledge. Well done.
JFreeChart 1.0.19
MacOS 10.13.2
Java 8 update 151
Using JavaFX
Edit:
I did more playing with this and found my testing method caused me an incorrect conclusion.
When I tested I started with one bar and noted the transparency of the CategoryMarker. I then added a second bar, then a third, then a fourth. Note, every change used the same instance of JFreeChart. With each addition the transparency decreased.
This morning I happened to be playing with economic data that involved adding and removing bars. I had my alpha adjustment (1/rowCount) commented out so it was the same on every chart rebuild. Every time I made a data change that caused the JFreeChart to rebuild I noticed the decreasing transparency again. But I wasn't always adding bars. I was adding and removing bars. The number of bars didn't matter. The number of times the chart rebuilt did. The transparency decreased with every rebuild, regardless of the number of bars, while the alpha value remained the same across rebuilds.
So many decades doing this and I still mess up.
Edit
Another interesting occurrence. When I do enough chart rebuilds (around a dozen) for the partial transparency to become fully opaque and then do a rebuild with additional columns, the new columns have my original transparency. The old columns remain opaque. After around a dozen rebuilds the new columns become opaque.
Even though I set alpha to 50 on every build, is it somehow cumulative toward opacity? Light bulb - the word cumulative.
Every rebuild did another addDomainMarker to every column (the cumulative part). I added clearDomainMarkers ahead of the for loop and the problem is solved. Now that's subtle.