Random Raster Chart Colorization
From fmepedia
Our WebCharter transformer can make nice bar charts. We can control multiple parameters including color scheme:
![]() |
![]() |
![]() |
However, we can't make each bar to have its own color, as we would easily get it in Excel:
Google Chart API allows setting individual colors to the bars - click here for details (http://code.google.com/apis/chart/colors.html#chart_colors), but at this point, FME does not expose this part through the transformer interface. It still can be done through a construction of a custom URL, but here is another solution that uses native FME techniques:
After we get an image from Google Chart,
we separate bars from the rest of the image contents (background, axes, and labels) with RasterExpressionEvaluator:
if(A[0]==A[1]&&A[0]==A[2],0,100);if(A[0]==A[1]&&A[0]==A[2],0,100);if(A[0]==A[1]&&A[0]==A[2],0,100)
This simple formula compares red, green, and blue values of each pixel, and if they are the same, we either deal with the background, or axes, or labels (of course, this will work if chart's color scheme is not black and white or grayscale). We set their color to 0, and make it NODATA. Now only our bars consist of data cells.
I already published an article about RasterExtentsCoercer. It this example, we use it to extract bars as vector polygons. Then we simply set some random color on each bar, and, using VectorOnRasterOverlayer, put them back on the image. Its original bars will be overwritten by the new colored ones, the rest - axes and labels will stay untouched:
We can apply some other coloring technique - for example, color may depend on the attribute value (check an example here - Loopy Art).



