I am using POI 3.12-beta1 and have code that creates a line chart with multiple datasets and named series in the legend. However, the default settings for line charts in poi
I couldn't find any solution to that same problem so I ended up trying to find some "creative workaround". It's not a clean approach at all, but I'll share it just in case.
It turns out that the default Chart POI interface doesn't allow to do a lot of operations (modify Axis and Legend, and that's about it).
I do work with XLSX files however, and the implementing XSSFChart class provides a bit more features, such as a setPlotOnlyVisibleCells method that does work in enabling/disabling that option in the "Hidden & Empty Cells" menu. However, that's not what we want!
If you look at the XLSX file format (which is basically XML), you'll notice there's a "dispBlanksAs" XML element as a child of the Chart element, and we'll want to set it to "gap". (POI won't set it, which is equivalent to set it to "zero").
Unfortunately, there's no such method in the POI API currently, so I had to resort to the following dirty code to get it working:
XSSFChart chart = (XSSFChart)drawing.createChart(anchor);
CTDispBlanksAs disp = CTDispBlanksAs.Factory.newInstance();
disp.setVal(STDispBlanksAs.GAP);
chart.getCTChart().setDispBlanksAs(disp);
This code is very likely reprehensible in many ways, but it works for me :)
An important note is that you'll need to have the ooxml-schemas 1.1 jar on the classpath for this to work. It won't work even with poi-ooxml-schemas 3.12, as it doesn't contain the definition for CTDispBlanksAs class.
Hopefully this feature will be supported in a future version of POI.