0

How to conditionally set colors for bar charts based on data values using poi?

I've created a bar chart with POI, but it either displays all bars in same color or each bar in random color.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
  • 1
    "created a bar chart with poi": How? Please show the code and mention the `apache poi` version you are using. The `apache poi` project is highly in development and how to create charts mainly depends on the `apache poi` version used. – Axel Richter Jul 26 '18 at 06:57
  • I use the latest version poi 3.17 – Vaishnavi Jul 26 '18 at 08:13
  • http://thinktibits.blogspot.com/2012/12/Java-POI-Bar-Chart-XLSX-Example-Program.html – Vaishnavi Jul 26 '18 at 08:15
  • referred this example – Vaishnavi Jul 26 '18 at 08:15
  • In [your linked example](http://thinktibits.blogspot.com/2012/12/Java-POI-Bar-Chart-XLSX-Example-Program.html), `org.jfree.chart.JFreeChart` is used for to create the chart. `Apache poi` is only usded to get the data for the chart to hand over them to `JFreeChart`using a `org.jfree.data.category.DefaultCategoryDataset`. Then `Apache poi` gets back a `*.png` picture for creating a `XSSFPicture`. So `apache poi` has nothing to do with the look of the chart but `JFreeChart` has. – Axel Richter Jul 26 '18 at 09:44
  • This was my reference:https://stackoverflow.com/questions/38913412/create-bar-chart-in-excel-with-apache-poi – Vaishnavi Jul 26 '18 at 10:57
  • [This answer](https://stackoverflow.com/questions/48336956/how-to-create-java-poi-bar-chart-combining-two-bars-value-like-given-image/48354955#48354955) contains code to set bar colors too. – Axel Richter Jul 26 '18 at 16:01
  • It has code to either set one color or randomly varying colors.. I need to use red and green color based on a true/ false data value – Vaishnavi Jul 27 '18 at 04:05
  • So you wants set background color of the bars in data points of a series different dependent of the serie's values? That's another question then. Please update your question and describe exactly what you wants. Please tell us what you have already - at least using a link to the used code, if public available - else by providing the code. Please provide some sample data and a screen shot of the needed result chart. – Axel Richter Jul 27 '18 at 05:23

0 Answers0