score:1
1) You use an index for filling the segments:
.attr("fill", function(d, i) { return color(i); })
So, when during the update the length of your data is changed (itemValue=0
case) the filling colour for the appropriate arc also changes.
You should set the domain for your color
scale:
const dataLabels = dataStructure[0].data
.map(function(item) { return item.itemLabel; });
Save the array of labels to dataLabels
variable
color.domain(dataLabels);
Pass it to .domain
property. After that, you can get the associated colour by the label name:
paths.enter().append("svg:path")
.attr("stroke", "white")
.attr("stroke-width", 2)
.attr("fill", function(d, i) { return color(d.name); }) // <--!!!
.transition()
.duration(tweenDuration)
.attrTween("d", pieTween);
paths
.attr("fill", function(d, i) { return color(d.name); }) // <--!!!
.transition()
.duration(tweenDuration)
.attrTween("d", pieTween);
2) You should pass the index of the dataset that you want to show after the page loading to update
function and to value
property of the slider configuration object. You have the length of data equal to 21, so you should pass 10 or 11 for showing the slider position at the middle.
var middleDatasetIndex = Math.floor(dataStructure.length / 2); // = 11
$( "#slider" ).slider({
value: middleDatasetIndex, // <-- !!!
min: 0,
max: 21,
step: 1,
slide: function( event, ui ) {
update(ui.value);
console.log(ui.value);
}
})
...
update(middleDatasetIndex); // <--!!!
Check the working demo.
Source: stackoverflow.com
Related Query
- D3 pie chart zero data point changes arc fill color
- Same color is showing in different arc of d3 pie chart
- Pie chart animation when data changes in plottable.js
- How to change color of a data point in line chart according to a condition?
- How to customize color in pie chart of NVD3
- D3 put arc labels in a Pie Chart if there is enough space
- Label names are not displayed from input data in pie transition chart of d3.js
- D3 Pie chart arc is invisible in transition to 180°
- hack for d3 pie chart with 'zero' data
- d3.js - Smooth transition on arc draw for pie chart
- How do I color labels for my pie chart in D3?
- D3 + React Native - Data point value not updating when X position changes
- Adding background color in d3 js bar chart using data values
- d3 donut chart arc retrieves wrong data
- Assign specific color to specific segment in D3 Pie Chart
- Changing color range in a d3 reusable donut chart depending on the number of data points
- Fill the inside of a pie donut chart d3
- Edit the data in a pie chart rather than create a new one
- how to display data from 1st point on words on y axis for line chart in d3.js
- Pie chart avoiding same adjacent color when rotating colors
- D3 update pie data with zero values
- changing color of d3.js pie chart label when hovering over slice?
- Javascript d3 pie chart doesn't pull data from JSON file with list of dictionaries
- Coordinates of each center's arc in a pie chart
- How to represent each data entry with a pie chart of its values?
- Redraw D3 Pie Chart with new data when clicking button or enter search field
- Animating D3 Arcs, with an Arc for each bound data point
- Fill same line color in to circle on Multi Line chart when mouse over and remove color from circle when mouse out
- d3v4 Saw Chart -- half pie chart example and arc based example
- D3 append a line or rect to fill pie chart values
More Query from same tag
- Can the links in D3.js Sankey Diagrams be anything besides cubic bézier curves?
- How to save d3 graph as image on local machine?
- Constraints on slider jquery + callng javascript function at page loadto call javascript function
- Text along an ark in a circle pack Text placement wrong
- Cannot read property 'length' of undefined, but can still print length in console
- Datamaps get list of country codes
- d3.js v4 d3.zoom and strange element order after zoom or pan
- make a tabpanel-like with SVG elements
- d3 arc transition error when toggling sweep-flag
- Properly show aliased legend items in dc.js (glitchless transitions)
- Adding a specific tick to a D3.js axis
- d3.js & NVD3 axisLabel with a £ (pound) symbol
- Adding a zoom function in D3 reusable charts using ES6 Classes
- Parallel coordinates multidimensional data not visualised in D3
- Reducing Large Datasets with MongoDB and D3
- select function not working in 3.5.4 version of d3.js
- d3.js How to create a separate element for each state in a country map?
- D3Js line graphs - align data points with ticks
- d3.v3 scatterplot with all circles the same radius
- Apply mapping to attached data
- Uncaught TypeError: d3plus.Pie is not a constructor
- How to add a link inside a D3 element?
- how to send a json object from index.js to html in node.js
- Create a D3 Bar Chart Using a Object
- Defining custom D3 symbols
- What is the relationship between the width/height specified for a d3.select element and the actual drawing area?
- Svg element gets stuck from time to time after rounding x and y
- Looking for a way to display labels on sunburst chart (could not find a working example)
- Can't fill circle background with color threshold
- How to position one end of a line element dynamically based on date?