score:2
Accepted answer
Here's a method of doing it with d3. You would need to alter the font size to your tastes. See the comments in the code.
var chart = c3.generate({
bindto: '#detail_chart',
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250, 400],
['data2', 830, 1200, 1100, 1400, 1150, 1250, 1500],
],
axes: {
data2: 'y2'
}
},
axis: {
y2: {
show: true
}
},
regions: [
{axis: 'x', end: 1, class: 'regionX'},
{axis: 'x', start: 2, end: 4, class: 'regionX'},
{axis: 'x', start: 5, class: 'regionX'},
{axis: 'y', end: 50, class: 'regionY'},
{axis: 'y', start: 80, end: 140, class: 'regionY'},
{axis: 'y', start: 400, class: 'regionY'},
{axis: 'y2', end: 900, class: 'regionY2'},
{axis: 'y2', start: 1150, end: 1250, class: 'regionY2'},
{axis: 'y2', start: 1300, class: 'regionY2'},
]
});
// set your labels here
var labels = {
'_1': 'label for region _1',
'2_4': 'label for region 2-4',
'5_': 'label for 5_'
};
// select all regionX rectangles in the chart
d3.selectAll('#detail_chart rect.regionX').each( function(r){
var region = this;
// attach a text element to the parent node
d3.select(this.parentNode)
.append('text')
// x offset is current region's x value + half its width
.attr('x', function() {
return region.width.baseVal.value/2 + region.x.baseVal.value;
})
.attr('y', 20) // change this to your liking
.attr('text-anchor', 'middle')
.attr('class', 'region-label')
.text( function(){
// this corresponds to the values you set when configuring the axis
// it is in the form <start>_<end>
var id = (r.start ? r.start : '') + '_' + (r.end ? r.end : '');
return labels[ id ]
});
});
.c3-region.regionY {
fill: blue;
}
.c3-region.regionY2 {
fill: yellow;
}
<!-- Load c3.css -->
<link href=" https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.7/c3.css" rel="stylesheet">
<!-- Load d3.js and c3.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.7/c3.min.js"></script>
<div id="detail_chart"></div>
Source: stackoverflow.com
Related Query
- How to add labels for regions in c3.js line chart or detail chart?
- How to rotate the text labels for the x Axis of a nvd3.js line chart
- 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?
- How to do wordwrap for chart labels using d3.js
- how to create labels for data in donut chart using d3.js
- How do I add labels to d3.js force bubble chart
- How to add a line on x-axis on a horizontal bar chart in d3
- How to add a fixed range vertical line to a D3.js chart
- D3: How to use exit().remove() for Multi-Series Line Chart
- 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
- C3js - combination chart with data labels only for line
- How to add background shading to D3 line chart
- How to add circles onto line chart path d3.js
- How do I color labels for my pie chart in D3?
- D3 : How to add labels top of in each bar in grouped bar chart
- D3.js v7 - How to make Y axis labels always show on screen for a scrollable chart
- How do I split labels for my donut chart to multiple lines using d3.js?
- How to add svg rectangles as background behind axis tick labels in d3js if ticks are inside chart
- How to create a multi-series line chart with series for each unique item in 1st column?
- how to display data from 1st point on words on y axis for line chart in d3.js
- How to add tooltip to line chart written in typescript and angular
- How do you add multiple lines to a D3JS line chart where the depedent variable data sources start at different positions along the range?
- how to add tooltip for donut chart in loop using d3js
- d3.js How to draw line chart with vertical x axis labels
- NVD3 Cumulative Line Chart : How to set different back ground color for specific X axis
- NVD3 line chart - how can I add on-graph series labels?
- How to extract nominal labels for d3 chart
- How to create a interactive d3 line chart to show data plots / labels on hover
- d3.js: The xaxis labels are showing bold for a line chart
- How to add a line at top of stacked bar chart with d3.js?
More Query from same tag
- D3 v5: "d" attribute in <path> tag not populating with values
- Implement Charts in Flutter using WebViews
- Access to svg from D3 library
- D3 negative value bar chart
- Drawing from a csv in D3
- Converting an Array of Arrays to an Array of Objects Using Built-in d3.js Methods
- Show svg foreign element with D3.js on mouse hover?
- Line graph using integers on y axis and strings on x axis
- how do I labels to the axis in this d3 example
- How to make a chart in D3 work in node.js
- D3 - Pie Chart & Force Directed Labels
- How to get intersection of link-edge and node in d3js?
- D3 transition between line interpolations
- nested circles in d3
- d3 v4 force layout tick function
- D3 js BoxPlot with already calculated data
- Can D3 force layout visualize multigraph?
- How to avoid marker and node overlaping in cola.js / d3.js
- D3js : mouseover of one element change opacity of several others elements
- How to Create Blank Lower 48 Map in Django JS
- d3 - nested selections/sub-item update issue
- Nesting or mapping data from key lower in json hierarchy
- How to position Pie chart on top using Nv.d3.js library?
- How to select all elements with a class that contains a str?
- Dynamically change width of d3.js sankey chart
- d3js world map with geoJSon
- How to force a specific amount of y axis ticks in d3 charts?
- How to use requirejs, jquery and d3 in a node express webserver
- D3.js SVG on OpenLayers3 interactive map
- Need help coloring in countries from an array, leave rest default color