I am using Wasil C3 angularjs directives (http://wasil.org/angularjs-directive-for-c3-js-tutorial) and there is also a sample plunker through compilation (http://plnkr.co/edit/w
I'm not sure if I understand correctly what do you mean by "subchart" and I'm not an expert in C3/D3 charts, but I'm not sure if you can change background color for a specific series, if that's what you meant.
But...
If you'd like to change background for whole chart, you can do this in (at least) two ways.
First way
Using your method, but with few small changes. This will alter background of whole chart, including legend, etc.:
d3.selectAll("svg > .bgRect").remove();d3.selectAll("svg").insert("rect", ":first-child").attr("class", "bgRect").attr("width", "100%").attr("height", "100%").attr("fill", "yellow");
Please notice the .bgRect class I added. It is meant to identify rectangle you are adding in order to be able to remove() it and re-add again. I did it, because if you just call insert() multiple time, you'll always see first rectangle inserted, because every added after it will be under/before it in HTML (prepended), i.e.
I've changed CSS selector, because yours was inserting rectangle element in place, where it wouldn't ever be visible.
Second way
(It is probably closer to what you need and in my opinion more proper way of doing this.)
By accessing charting area directly and simply changing it's CSS with d3.style() method:
d3.selectAll("svg .c3-zoom-rect").style("fill", "yellow").style("opacity", 1);
You can call it as many times as you want and it won't alter HTML markup while color will be adjusted.
Another way of achieving this would be adding/changing CSS class to this element with classed() and defining it's colors in regular CSS, i.e. bg-red, bg-blue etc.
One final thought
Consider changing d3.selectAll() to d3.select() with more specific selector. It might be helpful when using more then one chart on a page.
Hope it helps.