score:2
Accepted answer
You could separate legend
into two groups based on the data- one for the bars and another for dashed lines:
For the bar legend:
barLegend.append('rect')
.attr('x', this.state.width * 0.96)
.attr('width', this.state.width * 0.025)
.attr('height', this.state.width * 0.025)
.attr('fill', z);
For the line legend:
lineLegend.append('line')
.attr('x1', this.state.width * 0.96 )
.attr('x2', (this.state.width * 0.96) + 30)
.attr('y1', 10)
.attr('y2', 10)
.style('stroke-dasharray','5,5')
.style('stroke', z);
score:0
Figured it out. Used part of @valangars answer but added filters on both sections to only allocate the legend element with their desired style.
.filter(function(d){
return(d === 'dashed line data name');
})
.attr('x1', this.state.width * 0.96 )
.attr('x2', (this.state.width * 0.96) + 30)
.attr('y1', 10)
.attr('y2', 10)
.style('stroke-dasharray','5,5')
.style('stroke', z);
Thanks!
Source: stackoverflow.com
Related Query
- How to create a d3.js legend with both solid and dashed elements
- How to use d3.layout.cloud.js to create a word cloud with a csv containing both words and their weight?
- How do I remove all children elements from a node and then apply them again with different color and size?
- How to create floor plans that work nice with mobile and desktop browsers?
- How to make a dashed line legend with d3.js
- How can I plot positive and negative values for both axes in a scatter plot with d3?
- How to create a horizontal legend with d3.js
- How do you translate HTML elements along with SVG elements when zooming and panning with D3
- d3.js, how can i create an axis with custom labels and customs ticks?
- How to create left axis with variable tick interval in tick values and has same distance between tick value
- How to create elements (links) with 2 or more colors with CSS to make it look like a rainbow?
- D3.js V4 : How to create X axis with time and %H:%M:%S format
- How to create semi circle with d3.shape that start at 9pm and ends at 6am
- How do you get JSON data and create a line chart with d3.js?
- How can we add legend's value beside of legend with proper alignment and different color in dc.js
- Svg how to position elements lo left and right like with floats?
- how create a circle group a organization circle image and connect with curve line with D3.js?
- How can I create a basic bar chart with unique counts on the y axis and a category on the x axis?
- How to create a line chart with vertical line and different backgrounds?
- Create unique DOM elements with D3.js and update them but not append them again
- How to create a pie chart visualization in d3.js, typing the input manually and with smooth transitions
- How do I space out and wrap SVG text elements by individual word with d3.js?
- How to create a dashed line with arrows on each dash in d3?
- How to create an interactive collapsible tree diagram from csv with D3 and javascript?
- How to add two elements (circle and text) to SVG g element with D3js?
- d3.js Trying to create a grid and don't know how to access certain elements or bind to columns
- How do I create and write to a new file (csv) and have the browser download it with javascript or D3.js?
- how to make sankyplots with no color for source and target node and how to do legend to show the different colors of linkgroup
- How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?
- How to create elements depending on data in D3?
More Query from same tag
- d3 Selection merge error in TypeScript: Types of property 'merge' are incompatible
- HTML tooltip cleanup in d3.js
- SVG layer not rescale width map layer
- d3.js - shifting y-axis on stacked graph chart
- How to extend number of options in select tag using d3?
- Problems when interactively resizing and moving svg rectangles with D3
- Decouple update logic from useEffect in react+D3
- Highlight data label onmouseover for c3js chart
- D3 update pie data with zero values
- dc.js color pie chart slice color with color domain
- D3 - Reset Zoom when Chart is Brushed?
- How do I get the lines to render on d3.js multi-line chart?
- Use RxJS for D3 selection events
- SVG Circle element jumps upon scale transform
- D3.js: get text of selected dropdown option?
- How to set background color for svg text tspan without foreign object?
- set tickValues for y1Axis in linePlusBarChart in ng2-nvd3
- Create Nav/indicators on page based on tags
- How to display data with a specific property value in d3.js only on click/hover
- Parsing values from core-response in Polymer
- How do I build a grouped bar chart with scaleTime, using D3.js?
- d3.js-adding different colors to one bar in stacked bar chart
- D3JS with Kibana
- show additional data properties on mouseover in dc.js
- How to call function inside d3.json()
- d3.layout.pack text inside circle overrides other text in other circle
- How to switch from d3.svg.line to a choice that allows different coloured segments?
- Importing / Compiling d3 v4 with Webpack
- When using d3.js why must I call selectAll after select when appending new elements to an entry selection?
- d3 error from plotly: TypeError: e.getAttribute is not a function