set background color in chart - javascript

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 ?

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.

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.

dojox.charting.themes.Claro.chart.fill = "#F1F1F0"
dojox.charting.themes.Claro.plotarea.fill = "#F1F1F0"
dojox.charting.themes.Claro.chart.stroke = "#F1F1F0"
// Set the theme
chart.setTheme(dojox.charting.themes.Claro);

Using Jquery, you can do something like this:
$("#chartNode svg rect:eq(0)").attr("fill", "0");
$("#chartNode svg rect:eq(0)").attr("fill-opacity", "0");
So, basically you are accessing the element and changing the attribute manually. It is not very efficient way to do with, but it will do the trick.

Related

Heatmap.js Just want a red blob not multiple colours on the datapoint

I have created a heatmap and I just want my data point to be one colour instead of multiple colors like the standard one is, I'm not sure how to change the configuration of all the data points to do this.
I basically just want the colour in the middle to be the colour of the entire circle.
https://www.patrick-wied.at/static/heatmapjs/example-heatmap-googlemaps.html
On that website you will see an example of a heatmap and the data points all have blue bits around the outside I literally just want to make my points so they are just the colour in the middle of the data point.
For example the point in Florida I just want that entire circle to be red because it is red in the middle, instead of having the blue/yellow/green bits.
You just need to define the gradient in the heatmap and also set the blur value to cero:
For example:
var config = {
container: document.querySelector('.heatmap'),
blur: 0,
gradient: {
'1': 'red',
'0': 'white',
},
};
var heatmapInstance = h337.create(config);

KinetikJS Keep bounds while dragging an object

Heyhey,
while learning JS and using KineticJS I am stuck with a little problem.
As Iam not able to get my own code into a fiddle right now lets take this example:
http://jsfiddle.net/m1erickson/n5xMs/
If we make the white rect also draggable:
var white = new Kinetic.Rect({
x: 20,
y: 20,
width: 300,
height: 300,
fill: 'white',
stroke: 'black',
strokeWidth: 2,
draggable: true
});
the dragBoundFunc won´t work correctly anymore if the white rect is moved around. While debugging this with coda2, I found that when the white rect is dragged around, that the x and y attrs do not change.
Why is that so? How do I manage to make the dragBoundFunc work for moving parent-shapes?
thanks in advance for your help.
First of all:
I found that when the white rect is dragged around, that the x and y attrs do not change.
No, they don't, because they're defined statically. If you wanted changing values, you'd want to get the updated values within the dragBoundFunc. It might be as simple as calculating them the same way they are now, but inside that function.
How do I manage to make the dragBoundFunc work for moving parent-shapes?
In your example the white rectangle isn't a parent of anything, it's just a shape drawn on the same stage as the orange rectangle. What you want to do is make the white shape background and the orange rectangle both children of the same node, and drag that. The most direct way to do this here would be to make the layer itself draggable, e.g.:
var layer = new Kinetic.Layer({draggable: true});
But how you do this is arbitrary. The white and orange boxes might also be children of another Kinetic.Container, for example.

Add a background image to a connector in jsPlumb

I'm wondering if it is possible to add a background image to a connector.
My objective is to create something like this:
This way I could have an animated images in the background symbolizing the direction and type of the connection.
AFAIK it is not possible since the connection is made up of SVG object which itself acts as background image. You can try dashstyle option while tweaking paint-style and gradients to obtain appropriate arrow as shown in image. For more refer: API DOC
Sample Code:
jsPlumb.Defaults.PaintStyle = {
lineWidth: 4,
strokeStyle: 'rgba(123, 123, 123, 1)',
gradient:{
stops:[[0,"green"], [1,"red"]]
},
dashstyle: "7"
};
Result:
Note: Remember to use jsPlumb.setRenderMode(jsPlumb.SVG) since dashstyle doesn't work with jsPlumb.CANVAS (by default it is SVG)

Raphael.js map default fill colors

I am trying to familiarize myself with raphael.js. I want to create a USA map that already has default colors for each state and those colors stay there.
Here is what I came up with.
If you look at AK, I'm getting the default color loaded, but if I highlight another state, the default color for AK disappears. I want AK - and other states - to stay the same color.
Specifically, I don't know what is clearing out my AK full color. I think part of this statement is clearing out the fill cover when I mouseover a different state:
for (var state in aus) {
//aus[state].color = Raphael.getColor();
(function (st, state) {
st[0].style.cursor = "pointer";
st[0].onmouseover = function () {
current && aus[current].animate({fill: "#333", stroke: "#666"}, 500) && (document.getElementById(current).style.display = "");
st.animate({fill: st.color, stroke: "#ccc"}, 500);
st.toFront();
R.safari();
document.getElementById(state).style.display = "block";
current = state;
};
})(aus[state], state);
}
Any ideas where I might be going wrong?
It's been a while since I worked with Raphael.js but I think this is the line resetting your state:
current && aus[current].animate({fill: "#333", stroke: "#666"}, 500) && (document.getElementById(current).style.display = "");
Try replacing #333 with st.color or whatever that state's color is. If my assumptions are correct that would be something like aus['AK']??? You might have to capture the previous state's color. Let me know if that doesn't work and I can take a closer look.
Good Luck.
Drop your SVG of the USA into..
this
You can optionally remove OR LEAVE IN the mouseover code which is also generated.
Bryan Allo touches on part of my problem, but ultimately it is the animation code that is causing problems. I never figured out how to animate to similar color hue and ditched the following code completely: st.animate({fill: st.color, stroke: "#ccc"}, 500);
The end result is a site that lets users create their own presidential race predictions by state. Here it is.

Setting the background color of a Dojo gauge

I'm creating some Dojo 1.8 GlossySemiCircularGauge at runtime via javascript and I'm trying to set the background color of the gauge. I'm looking to set the color outside the gauge, not the gauge it self. I'm creating the gauge with syntax like this:
glossyCircular = new dojox.gauges.GlossySemiCircularGauge({
textIndicatorColor: '#FFFFFF',
background: "[0, 255, 0, 0]",
id: NewID,
Max: 20,
value: newValue,
noChange: "true",
width: wid,
textIndicatorPrecision: "2",
color: '#101030',
height: hei
}, dojo.byId(NewID));
Since the gauge is drawn with SVG, it doesn't work to set the background color of the container div. Is there a way around this?
The correct format for background is:
background: { color: "rgba(0,0,0,0)"}
Set the alpha channel to zero, so it will get transparent and you can adjust the background color via parent <div>.
See and play with a working example at jsFiddle: http://jsfiddle.net/phusick/E9YNM/
EDIT: I added dojo/domReady! to the example, so now it works not only in my browser.
EDIT2: background: [0,0,0,0] works as well, so just get rid of those quotation marks to have array instead of a string.

Categories

Resources