For reference: in the comments on @bencripps answer, the OP talks about using
tickValues is actually if you want to specify custom ticks within the scale you're using. Right now, you're using a linear scale:
so it expects your tick values to be points on that scale where it can draw ticks. If you had something more like
xAxis.tickValues([1, 2, 3, 4, 5, 6, 7]), it should work.
However, it sounds like you don't actually want a linear scale. d3 also has other scale types, and it sounds like the one you want is an Ordinal Scale. Ordinal scales are the scales you typically think of for bar charts; they're a type of scale that has a discrete domain. In this case, you could try changing your scale to something like:
so it uses an ordinal scale instead. Since you're using dc.js, you'll also need to specify
so that it knows to use ordinal marks.
Here is some simple code for adding an X axis; you will have to fiddle with the domain, and range to get the desired length, and number of ticks.
var XaxisScale = d3.scale.linear() .domain([0,150]) //you will have to set the domain, not sure what you want .range([0, magValue.length) var xAxis = d3.svg.axis() .scale(XaxisScale) .ticks( magValue.length ) // this you will need to set as well var xAxisGroup = $('"#dc-magnitude-chart').append("g") .attr('class', 'axis') .attr('transform', 'translate(5,8)') .call(xAxis);
.call(xAxis) is what is actually appending the X axis to your chart.
- Add labels to bar chart D3
- D3 : How to add labels top of in each bar in grouped bar chart
- Dimple.js - Add data labels to each bar of the bar chart
- Add labels under every bar of the grouped bar chart on D3
- D3 - To add Data Labels to a simple bar chart
- Add labels to a d3 bar chart
- How to add updating labels in D3 Vertical Bar Chart in an Ember Application
- Add labels to bar in d3 chart
- D3 Stacked Bar Chart add Data Labels and solving D3 Label Placement
- d3.js How to add lines to a bar chart
- How do I add labels to d3.js force bubble chart
- d3.js bar chart sorting: can't figure out how to sort x-axis labels along with bars
- How to add a line on x-axis on a horizontal bar chart in d3
- How to add space between bars in a grouped bar chart in a nvd3 grouped multibar chart?
- D3 bar chart needs to add arrow and text in particular bar
- Ordering a bar chart labels in dc.js (again)
- 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
- Add border-radius bar chart d3
- x axis labels overlapping for grouped category bar chart in d3
- d3 show labels only for ticks with data in a bar chart
- Adding text labels in middle of each bar - stacked bar chart & Mouse Over Events
- add Y axis labels to D3 bar from json data name attribute
- c3js - D3js - Customize labels in a simple bar chart
- Stacked Bar Chart Labels - D3
- Add Zoom to a Grouped Bar Chart that uses a scaleBand
- NVD3 Horizontal Bar Chart labels too long
- D3.js bar chart - axis and labels not working / transitioning
- trying to get the circles next to the y axis labels in bar chart d3.js
- D3 Positioning of Text Labels on Bar Chart
- Nivo bar chart axis labels overlapping
More Query from same tag
- d3 bar chart- How do I automatically change font-size of value so that it fits within bar
- Setting D3 svg.transition to go from slow to fast to slow
- Appended bars wont draw on svg element
- In D3, why Do I need to choose select a dummy object to create something?
- D3.js join data from multiple csv files
- How do I make a simple d3 chart with Firebase data?
- d3js move a node without dragging
- GeoJson and D3.js multipolygon
- Display large number on y-axis in python-nvd3
- D3 Bar Chart with Variable X and Y(variable width and height for bars)
- D3js dynamically attach circles into a line with drag and drop
- Forced-Directed Graph and localstorage
- How to flip x-y axis on click using d3
- D3.js change time format and export data into csv
- How to find the coordinates of a text in an svg?
- d3.js event when two radio buttons selected
- Different height of nodes in a cluster dendrogram d3.js
- C3js Quit curve on data point with zero value
- Add data points and text to lines on a multi-bar graph with lines
- how to sort dates in jquery
- Animated Ripples using jquery
- D3.js -- Ordinal scale (version 3 to version 4)
- Right to Left tree direction in D3
- d3.js translate header text above or below a circle based on array index
- Simple D3 demo not working with altered structure
- Dimple.js Axis Labels
- Add a circle to a d3.js map
- How to add images to c3.js generated charts
- How to display values of d3 animated sparkline graph into tooltip?