Reputation: 780
This newbie question relates to the InfoVis Visualization project.
Whilst the color and other properties of a node can be defined within the JSON data:
id: "",
name: "",
data: { color:""},
I would like to set the color of a node based on another element, say for example the value of "risk":
id: "",
name: "",
data: { risk:"1"},
e.g.
if(node.data.risk == "1") {
node.setData('color', '#ffcccc');
What is the best way to change the color of a node based on the content of data when the JSON is loaded.
update:
have this solution working so far:
onBeforePlotNode: function(node)
{
if(node.data.risk == '2')
{
node.data.$color = '#ff5050';
}
if(node.data.risk == '1')
{
node.data.$color = '#ffcccc';
}
if(node.data.risk == '0')
{
node.data.$color = '#1aff1a';
}
},
however, it does not render the new colours until one of the nodes is clicked.
Follow up question: provided this is a reasonable solution how can the new colors be rendered when the visualisation first loads?
update:
Code had to be placed at end of page.
Upvotes: 1
Views: 63