score:1
Accepted answer
there are several ways for positioning the y axis in the centre, this is one of them:
find the maximum absolute value in your x scale...
var maxvalue = (math.abs(d3.min(data, function(d) {
return d.interactions;
})) > math.abs(d3.max(data, function(d) {
return d.interactions;
}))) ? math.abs(d3.min(data, function(d) {
return d.interactions;
})) : math.abs(d3.max(data, function(d) {
return d.interactions;
}));
and use this value to set a symmetrical domain:
x.domain([maxvalue*-1, maxvalue]);
this is the fiddle: https://jsfiddle.net/b1xhyo6c/1/
Source: stackoverflow.com
Related Query
- How do I centre the Y axis in a D3 Tornado Chart
- dimple.js How can I change the labels of a chart axis without changing the data?
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- How to cut y axis to make the chart look better?
- how to make the x axis scrollable in a d3 line chart graph
- How to zoom only on the X axis in a line chart in d3.js (v7)
- How can I create a basic bar chart with unique counts on the y axis and a category on the x axis?
- How do I update the y axis of the chart using D3 js
- How to rotate the text labels for the x Axis of a nvd3.js line chart
- How can I make a bar chart starting from the 0 point of the y axis and not from the bottom of the svg?
- How can I fix my chart so that the scale of the x axis is defined by a group of labels?
- d3js - Stacked Bar Chart in Horizontal Axis - How do I set x so the bars are seperated?
- d3 Plus bar chart how to force fixed max y axis range independent of the max data value
- How to make bar chart with additional vertical lines below the x axis
- How to plot stacked bar chart according to the custom Y axis in D3
- How to make axis label of stacked bar chart in the middle of ticks chart in D3?
- How do you rotate the x and y axis in D3 bar chart
- How can I get the D3.js axis ticks and positions as an array?
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- D3 grouped bar chart: How to rotate the text of x axis ticks?
- how to set the domain and scale on an axis on a nvd3.js multiBarChart
- Make simple bar chart using C3 with separate columns on the x axis
- How to display the value for the final tick on axis in D3?
- D3 bubble chart / pack layout - How to make bubbles radiate out from the largest bubbles to the smallest?
- How to flip the Y axis on my D3 graph?
- how do i customise the c3.js chart to get like this
- how to add legend to a pie chart using D3js? And how to centralise the pie chart?
- How to format the Y axis values on Rickshaw Graphs
- How to plot animated line chart using d3 while the data table is required to be updated every 1 second?
- How to change the viewfinder (focus chart) of a NVD3 line chart programmatically?
More Query from same tag
- d3js - Create custom scale - Positive and negative logarithm
- How to reload a Flask app each time it's accessed
- d3 range/domain returning negative values?
- Freeze Y-Axis label in d3.js
- Multi series chart (D3) with missing values
- d3 Uncaught TypeError: n.domain is not a function
- How do I get the width of a bar including padding in d3?
- Enter/update/exit on two-levels, without nesting
- Create an interactive 3d scatter plot with D3.js and Three.js with json data
- Get only non-filtered data from dc.js chart (dimension / group)
- Multiple line transitions in d3.js
- Panning is not working properly with scatter plots
- d3.json works but $.getJson fails
- Calculate width of text before drawing the text
- how to update data in D3 version 4?
- nvd3.js ugly labels in pieChart
- d3 Links Not Properly Hiding
- Creating multiple lines using json file with coordinates in d3.js
- Why are cross-origin Image requests blocked by Cytoscape.js but not by d3.js?
- D3 custom attributes not being selected
- Using D3 to retrieve a TopoJSON U.S. county from coordinates
- Formatting dates as financial year in DC.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
- Unable to make pie chart from the dataset
- No figure output in htmlwidgets in R
- How to generate graphs and charts on the fly using web2py
- Is there anything like D3's Nest functionality in Objective-C?
- D3.js updating the code, Error: Cannot read property 'axis' of undefined?
- Zooming datasets in d3.js
- Cannot protect the color of my svg when using mouseover method