score:1
Accepted answer
In your style fill
just create a function and compare the two values and return a color based on the condition like so:
svg.append('path')
.data([drawData]).attr('class', 'area')
.attr('d', area)
.style('fill', function(d){
for (i in d) {
if (d[i]['dailyConsValue'] < d[i]['targetConsValue']) {
return "green"
} else {
return "blue"
}
}
})
.transition().duration(2500)
.attrTween( 'd', this.tween( drawData, area ) );
This will work based on only the last value of the data. If you want different colors at every point of the chart depending on your condition, you will have to create a linearGradient
with multiple color stops (dynamically) as far as I know.
Now to create a linearGradient
, I have created a linear scale using d3 to calculate the offset for color stops and assign color based on your condition. To dynamically create a linearGradient
refer to this fiddle
Source: stackoverflow.com
Related Query
- Different color between line and area graph
- Color the area formed between Line Chart and Threshold line
- d3.js change color and size on line graph dot on mouseover
- d3.js line and area graph - want to add a extra line defined by two points and representing a threshold/minimum value (for ease of viewing)
- D3 Transition. Working with multiple lines on line graph and would like to transition smoothly between lines when button is pressed
- Draw a d3 trend line with different color and width for different segments
- Create a Line graph with Dots and Labels using 2 different data sets
- How do I remove all children elements from a node and then apply them again with different color and size?
- D3 - Difference between basis and linear interpolation in SVG line
- D3.js - Is it possible to animate between a force-directed graph and a node-link tree?
- D3.js adding intercept point and area between two paths
- D3 line graph appearing as area graph
- Transitions using line graph and Rickshaw
- c3 graph in a dark background; how to change axis and tick value color
- D3.js - Line Graph: Area path goes over x and y axis on zoom
- How to hide and show points on a line graph
- Starting Transitions and Animations With Area Graph in D3.JS
- Drawing different colored "strokes" between center and different nodes in a D3.js tree
- How to increase width and height of plotly area graph
- D3.JS: Zig zag line on y-axis between zero and start value
- How to position NVD3 line graph above all other area / bar graphs?
- Considerable difference between Firefox and IE displaying plot line chart
- How can I color one Y-axis line different from the other grid-lines?
- How to select and deselect a svg line and change its color on selection and deselection using d3.js and javascript , jquery?
- d3 line and area charts not updating with new data array
- Arrow head and link of the same color in D3 js graph
- Different tick sizes on the Y axis of a D3js line graph
- Need help plotting area between multivariate lines - not from axis to line
- How can I make a dynamic line between 2 elements not knowing their positions in x and y?
- How to properly assign separate colors to different lines and line series in D3 Dimple?
More Query from same tag
- How to dynamically change the color of a country on d3 map
- d3.js collapsible force layout with all the nodes collapsed
- D3 Force Layout Colour and Zoom
- grouped category bar chart with different groups in d3?
- D3.js Timeline does not filter Points of interest on map at all
- Filtering in stacked bar chart using d3 v3.js by changing data on input selection
- I'm unable to remove correctly a node from a D3 force graph
- NodeJs MongoDb Result without getters and setters
- How to use d3.js and node?
- Error: Invalid value for <path> attribute d="MNaN,NaNA5,5 0 1,1 NaN,NaNL0,0Z"
- Typescript/d3, can't dynamically provide symbol types
- Unnecessary gap in line graph paths
- Group and count json data in queue() in d3.js
- How to define custom time interval in d3.js
- Smoothing arcs/plot points in D3.js/GeoJSON/TopoJSON/Shapefile (somewhere along the way)
- How to move d3 ticks on y-axis
- loading json file to d3.js
- d3 - label placement for a nested pie chart
- Relative positioning of generated svg objects in D3
- Plotting line chart with date vs frequency in d3 by angular
- Temporary upload a file to use it - javascript
- How to add multiple arcs to globe
- I cannot scale my font-size with D3 domain and range...?
- Processing hierarchical JSON data with d3.js
- how to focus the clicked bar in C3.js bar graph?
- D3 - add class to selected parent
- d3.js linechart different interpolations for different lines
- Labels and images for D3 nodes incorrectly show at top left of screen
- how to inline data for D3 bullet chart
- Accessing nested JSON structure in D3