score:1
Accepted answer
I don't think there is a an option to put logic in the fillkey selection. I'd recommend processing the data to assign a fillkey before giving it to Datamaps. I made a codepen to demonstrate. Also, the "fills" data has duplicate keys and hex values that do not match the color described.
var stateData = {
AZ: {
userVisits: 5
},
CO: {
userVisits: 15
},
DE: {
userVisits: 32
}
}
function addFillKey(mapData){
for (var mapDatum in mapData){
var userVisits = mapData[mapDatum].userVisits;
if(userVisits < 10){
mapData[mapDatum].fillKey = "lightBlue"
}else if(userVisits < 20){
mapData[mapDatum].fillKey = "justBlue"
}else{
mapData[mapDatum].fillKey = "mediumBlue"
}
}
}
addFillKey(stateData);
var map = new Datamap({
element: document.getElementById('container'),
scope: 'usa',
fills: {
'lightBlue': '#cc4731',
'justBlue': '#306596',
'deepBlue': '#667faf',
'mediumBlue': '#a9c0de',
'deepBlue': '#ca5e5b',
'defaultFill': '#eddc4e'
},
data: stateData
});
Source: stackoverflow.com
Related Query
- Datamap - Change color depending on value
- D3.js: Changing the color of the bar depending on the value
- c3 graph in a dark background; how to change axis and tick value color
- D3.js stacked areas with color change above specific value
- How to change table cell color based on numeric value from .csv report AND when tables are dynamically created?
- How do I change color of path element when its value is selected from dropdown
- D3 Reactangle Bar with color gradient depending on value
- nvd3.js - display specific color for each bar in multibar vertical chart depending on range of value
- Change text color depending on background using D3
- D3 change the background color of an element based on it's data value
- Find color depending on integer value - quick algorithm
- Change node color depending on status
- parallel coordinates : setup color depending on value of dimension
- d3. change color of nodes individual depending on array content
- d3.js change color and size on line graph dot on mouseover
- NVD3/D3 change y axis minimum value
- How to change the color of two circles upon overlap?
- How to change line color in d3js according to axis value?
- Change label text color in row chart
- Change color on a map D3
- D3 color change on mouseover using classed("active",true)
- nvd3.js - unable to change color of line in line chart
- How do you change the last tick value in D3.js?
- How do I change color of a bar in Vega-lite Bar Chart?
- How to change color of the dots in D3.js to reflect data on y scale?
- Color each arc of sunburst based on size value
- D3 Angular confusion: fill color doesn't change
- Change value on legend in dc.js
- Change the color of nodes on double click in D3
- Change color of selected map feature in d3.js
More Query from same tag
- Wait for d3 to load
- d3.geo.path() to draw multiple routes on a map
- d3.csv.parse only parses first line of csv string
- Combining two charts in one div - d3 / css
- How can I calculate the degree of nodes in D3 v5?
- Inconsistent d3-legend positioning when using an external font
- Real-time data with D3
- Change the size and angle of D3 geoCircle
- How to chain d3 transitions?
- Making D3 like Force-Directed Graph with PNGs
- Cannot set d3 axis to only integers
- Modifying donut chart to "progress donut chart"
- What's the best way to make a d3.js visualisation layout responsive?
- confusion calculating x/y coordinates based on rotation angle with D3 + svg transformation
- Issues with preserveAspectRatio, viewBox and layout.size()
- Chart Drawn Incorrectly when using NVD3
- D3js code when called twice duplicates the graph instead of refreshing
- Collision detection for nodes of varying sizes not working as expected
- How to define individual link style on react-d3-tree
- How to zoom on a map using d3 on canvas?
- How to display Temperature, Wind Direction/Speed live data from GFS / NCEP / US National Weather Service on globe?
- Color map using list and if/else in d3
- How can to implement FontAwesome v5 icons in D3js v4 and Angular 4
- In multiline chart, at the end of each line i want a small circle and the value of the end point using d3.js
- d3.js download graph as svg image
- Offset Line stroke-weight d3.js
- How can I reference this data in this JSON file?
- Why selectAll("element") is important in d3js while generating a chart
- Trying to make vector map of US counties with d3.js render fast
- Unable to make jQuery resize event work as expected