R – Action Script 3: How to set chart area background

actionscript-3backgroundcharts

I'm building chart in Action Script 3.0 and need to set background color of the area where chart is drawn. I found solutions how to set background color for all chart, but it's not exactly what I need: I need to color chart part where plot is drawn

Best Solution

in your chart you need to add a background element with a CartesianDataCanvas. Then in the AS you can add elements to that chartBackground. For Example

<mx:LineChart id="chart">
  <mx:backgroundElement>
    <mx:CartesianDataCanvas id="chartBackground" includeInRanges="true"/>
  </mx:bakgroundElement>
</mx:LineChart>

...

private function addToBackground_():void
{
  var box:Canvas = new Canvas();
  box.setStyle("backgroundColor", "green");
  box.setStyle("backgroundAlpha", 0.5);
  box.width = 100;
  box.height = 100;
  chartBackground.addDataChild(box, new CartesianCanvasValue(chart.horizontalAxis.minimum, 0),
CartesianCanvasValue(chart.verticalAxixs.maximum, 0));
}

This will add a transparent green square at the top left corner of the plot

Related Question