score:15
You can set the tick values of an ordinal axis explicitly using d3.svg.axis().tickValues(*array*)
.
But this is an odd way to do it because it dangerously separates your keys and values, meaning you have to take care to manually align the scales and make sure that your data corresponds correctly. It helps to group the keys and values in a single object and then use the format:
axis.domain(array.map(function (d) { return d.value; }))
to map your axis domains.
I have reworked your data and fiddle to do it in what I see as the more d3 way. (Also note that I made some other changes just for fun, namely improved the margins and cleaned up the axis alignment, etc.)
Source: stackoverflow.com
Related Query
- Creating a Text Labeled x-Axis with an Ordinal Scale in D3.js
- dc.js bar chart with ordinal x axis scale doesn't render correctly
- D3.js zoom with Ordinal axis not working - Issue with setup of scale in zoom behavior?
- limit number of tick marks in d3.js x axis with ordinal scale
- Creating a d3 v4 histogram with an ordinal scale
- D3.JS- Format tick values with an ordinal scale axis
- Inversion with ordinal scale
- d3 time scale x axis with unix timestamp
- nvd3 scatter plot with ordinal scale
- Horizontal pan with ordinal x axis in d3
- Creating an endless horizontal axis with d3 v4
- With D3, how can I set attribute ("fill", "none") of axis path and line, but not text (without editing stylesheet)
- D3.js v5 - Creating a relative, zoomable timeline-like axis on a linear scale
- javascript d3 line graph with ordinal x axis
- D3 - ordinal scale labels with same names
- How to use d3.symbols with an ordinal scale
- Is it possible to make axis ticks with appended text to have dynamic padding in d3?
- Get In between points of an Ordinal Scale Axis in d3
- Creating multi-scale, nested, ordinal bar charts with D3
- Give outerspacepadding at x axis with time scale in d3 js
- Creating a radial chart with a different color for each axis label
- DC JS: remove outer padding for line charts with an ordinal scale x-axis?
- Creating an axis with absolute value in d3
- Creating a d3.js linear scale with multiple domains?
- d3JS Histogram with ordinal scale
- Creating axis with custom (range) values
- Create scatter plot with ordinal scale in d3 version 4
- d3 xAxis with ordinal scale and a click event?
- d3: replace a number value with text on x axis
- DC bar chart Y axis with integer scale (not multiplicated)
More Query from same tag
- How to change opacity on second click?
- Preparing Data to Plot in d3.js from Ruby on Rails Database
- I cannot scale my font-size with D3 domain and range...?
- How to format brushed time axis (with context-dependent values)
- D3 stacked bar sorting - chart only updating once
- Offset Line stroke-weight d3.js
- dot (symbol) color on d3.js multiline chart
- Stroke on rect in D3 blurry
- Is it possible to have a scrolling div that adjusts to the number of bars in a dc.js rowchart
- Typescript/prototype directly onto d3 object and d3-context-menu
- How D3 key function in data binding works
- Semantic zoom on map with circle showing capital
- Stacked Bar Graph in d3js
- Tooltip doesn't disappear on mouseout
- d3.js: Nesting data - key returns undefined for all data
- Adding a Tooltip in D3 to a Google Maps Overlay
- Restrict line chart zoom in upto hours in dc chart library
- d3js wrong or no text in x-axis
- Cartogram using angularjs and d3 TypeError: undefined is not a function
- D3 linear gradient baseline doesnt sit on the average line. How do i put the lineargradient line on the exact spot I intended?
- d3 zoom function issues in v4
- Create bend points in links with drag and drop using D3 or javascript
- Can I animate D3 pie arcs if I'm not updating data?
- Angular nvd3 HorizontalBarChart displayed difference format in the barLine and the holizontalLine
- D3 js chart issue
- Making a grouped bar chart when my groups are varied sizes?
- d3 bar chart - trying to line up tick to bar
- Merge objects that share a common key or value
- d3 - multiple overlaying charts with custom DOM element
- How to correctly reuse D3.js component in Angular 2?