NVD3: labels for second y-axis in MultiChart? - d3.js

Is it possible to specify a label for the second y-axis in an NVD3 (1.8.3+) MultiChart? The following correctly sets a label on the left-hand side of the graph, but not the right:
chart.yAxis1.axisLabel('Liters');
chart.yAxis2.axisLabel('Gallons');

I had the same issue, turned out that the right side was being cut off. I solved it by including a margin when I defined the multichart model.
`var chart = nv.models.multiChart()
.margin({top: 30, right: 90, bottom: 50, left: 70})
.color(d3.scale.category10().range());
That fixed the problem for me, might be worth checking it out. The multichart example on github also has a .margin setting in their code.

Related

Ensure value labels are displayed

I want to keep value labels outside my amChart graph. The problem is that when value label value is over 9999 then I cant display it's all content.
In this example values should be:
25,000
20,000
15,000
10,000
5,000
First digit is missing. I am dealing with this only by setting panel's margin
"panelsSettings": {
"marginLeft": 40,
"marginRight": 20,
},
Is there any more convienient way to be sure that labels are fitting? hardcoding margin seems to be overkill.
This is my example chart: https://jsfiddle.net/29w35txy/1/
As I mentioned in the comments above, it seems that this issue is depending on the default Browser font.
So it is working in Chrome (left), but does not work in Firefox (right) for me:
Beside that you can prevent this by increasing marginLeft of your panelsSettings which you are already using:
"panelsSettings": {
"marginLeft": 60,
// ...
},
Here I forked you fiddle to show the result.

Dc.js: Scrollable rowChart with no gap?

It seems like the height and fixedBarHeight cant both be used in a rowChart. Ids like to use fixedBarHeight so all the bars have the size I want, and the chart to be in a scrollable div so that the numbers of bars define the height of the chart. Is this possible?
#ialarmedalien made this block, which introduces a dc.axisChart to separate the axis of the row chart from the actual chart.
Then you can use conventional overflow-y: auto on the row chart div.
Here is a related issue on dc.js.
The dc.axis addon mentioned by #Gordon will solve the problem with the axis in a scrollable div, but not the problem asked. By default, the axis will only appear at the bottom, not before.
To solve this, add one div after the row chart div, this div will contain a copy of the axis.
<div id='row-axis'></div>
Then initialize this axis in the javascript
dc.axisChart('#row-axis')
.margins({ left: 10, top: 0, right: 10, bottom: 10 })
.height( 50 )
.width( 300 )
.dimension( dimension )
.group( group )
.elasticX( true );
Then change the margin of the row chart to 'glue' correctly with the axis. They also must have the same width.
.width(300)
.margins({ left: 10, top: 0, right: 10, bottom: 0 })
Then , in the css
div.dc-chart {
float: none;
}
Dont forget to include overflow-y: auto for the row style. Then you get:
This however doesnt solve the gap problem if your height is too large (or too small) compared to the fixedBarHeight.
But now your margin is zero, so the proper height is easy to calculate (but you must pass the gap value, which has 5 by default). Assuming N=chart.group().all().length, then do:
.fixedBarHeight(X)
.height(X*N + gap*(N+1))
Which will give you:
Worth mentioning that at this point you dont even need the fixedBarHeight anymore. Simply setting the height using XN + gap(N+1) will result in dc auto setting this value to X.
Based on: https://bl.ocks.org/ialarmedalien/0a4bf25ffc0fb96ae569a20f91957bc1
Just add style="overflow-y: auto; height: 300px;" in your rowchart div. It should work.

How to make c3chart take 100% of the width

I use the library C3.js to build a graph on the page. The graph should occupy the entire width of the screen (because I hidden legend and axis), but chart zone always has an indent about 1% from window's width.
Can I make this?
Example
axis: {
y: {
show: false
},
x: {
show: false
}
Very Strange, you can put negative padding to get rid of it, I have no idea why its there either. you can add padding: { left: -20, right: -20 } to your chart object as quick hack around.
https://codepen.io/anon/pen/oBxPPL
c3js Padding Options

Is the length of the text in a nvd3-legend adjustable?

I'm using d3 and nvd3 to visualize some data in a graph. Now, no matter how many graphs i have, the legend above the (line)graph will always be shortened with trailing dots at the end.
Is there a way to adjust the legend in a fairly comfortable way? If so, how would i adress the legend and its properties?
I found the answer myself.
To keep the text from shortening, you can use chart.legend.align(false)
Thanks Reteras it did the trick for my PieChart, here are my legend chart options (typescript version)
Just change the margin to adjust the position
legend: {
align: false,
height: 200,
margin: {
right: 50,
top: 25,
left:0
}
}
legendPosition: 'right',
legend: {
maxKeyLength: 100,
padding: 40
}
This will set maximum text length of legend as 100 and ensures text cut off due to ellipsis.

nvd3.js How to disable tooltips for one serie only

I'm trying to disable the tooltip for the line serie of my chart and leave the one of the bar serie. I can't really see how I can do it.
The problem I have with both series' tooltips enabled is that I cannot see the tooltip of the bar serie because it's always selecting the one from the line which is closer. Maybe it's possible to trigger the tooltip if the mouse is closer to the point? at the moment it's triggering it at around 10-20px away from the point.
This should do it:
var chart = nv.models.linePlusBarChart()
.margin({top: 30, right: 60, bottom: 50, left: 70})
...
;
chart.lines.interactive(false) // add this line

Resources