Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set background color in chart

I am using a theme, but i want to set background color around the chart to white or transparent or something.

I am trying this code:

  var myTheme =  dojox.charting.themes.PlotKit.orange;

  myTheme.fill= "white";

  chart10.setTheme(myTheme);


chart10.addPlot("default", {
    type: "Pie", 
    labelOffset: -30,
    radius: 150,
    startAngle: 45,
    font: "normal normal 10pt Tahoma",
    fontColor: "black",
    labelWiring: "grey",
    labelStyle: "columns",
    htmlLabels: true,
    plotarea: { fill: "#000" }
});

But this code didn't works, none alteration is visible.

How can i set the color background ?

enter image description here

like image 987
anvd Avatar asked Jan 23 '12 23:01

anvd


2 Answers

I believe you have to set both the chart.fill and plotarea.fill properties.

  myTheme.chart.fill= "white";
  myTheme.plotarea.fill = "white";

If you do console.debug(myTheme) you can inspect all the properties of the theme object. I usually have to experiment a little before I find the right ones.

like image 97
Frode Avatar answered Sep 30 '22 15:09

Frode


I know this is old, but I had a situation where I was creating a pie chart and needed to change the background color behind the pie chart. I tried this solution, but it didn't work because I wasn't assigning a theme. I am creating it this way:

var pieChart = new Chart("myDIV");
pieChart.addPlot("default", {type: "Pie"});
pieChart.addSeries("Series A", pieString);

My pieString is where I am combining my variables together to form the pie. Basically, I concatenate a series of statements like this:

{y:200, tooltip: "layer", color:"red", text: "myText"}

I join those strings together and assign it to my pieString variable.

When I set up my chart, I got a standard white background behind it, which doesn't work well for my colored background since I wanted it to blend. There are two rectangles that make up the background. You can change the larger and furthest back one through pieChart.fill = "something", but the inner one didn't change.

The way I solved this for me is like this.

function ClearChartBackground() {
    var sumDivRects = document.getElementById("chartDIV").getElementsByTagName("svg")[0].getElementsByTagName("rect"); //so I am getting the rectangles that are part of my chart div

    var firstRect = sumDivRects[0];
    var secondRect = sumDivRects[1];
    firstRect.attributes.item(1).value = "0";
    secondRect.attributes.item(1).value = "0";
    //this drills down to the 'fill-opacity' attribute that can then be changed to make it transparent


}

As you can see in my photo, the original background was white, which doesn't work well on my gray background. After running my function, it is changed to transparent.

I am posting this because it took me a pretty long time to find out how to change this since I am having Dojo render it for me. I came across this post, but I didn't get much help from it since I wasn't doing a theme.

This is my bad clip showing the difference

like image 31
Branco Avatar answered Sep 30 '22 14:09

Branco