简体   繁体   中英

Scientific notation on axes in plot from django-nvd3

I have tried for hours now to find any documentation on this, but it doesn't appear to exist. After battling for days to get any of the methods for creating and showing plots in Django to work, I finally managed to get nvd3 for django working. But now I am having problems with the notations on the y axis of my plot. Because my values are very small (at most 1.0e-4) I want to use scientific notation with exponentials.

The command to do what I want appears to be chart.y1Axis.d3.format(".2f") in d3, but I have no clue how to apply this in nvd3. Does anyone know how to deal implement it?

Also, on the x axis I have the opposite problem that the values are large. Because the plot is log-log the routine puts a ticklabel on 10, 20, 30 40,...100, 200, 300, 400..and so on, but I want it to only plot for every order of magnitude (10, 100, 1000, 10000 etc.). What is the easiest way to automate this? Would it work if I tell the routine to always print the ticks for 10, 100, 1000, 10000, and so on up to an exceedingly high value, even though my plot wouldn't reach as high? How would I do that?

This is how the plot looks like right now:

地块视图

Use this for scientific notations on y axis

 chart.yAxis.tickFormat(d3.format('.02e'));

for x axis problem try this

this will return log for the x values.

chart.x(function(d){return Math.log10(dx)}) ;

and this will again covert it to normal number, your scale will be logarithmic

chart.xAxis.tickFormat(function(d){ return (Math.pow(10,d)).toFixed(2);});

Here is the JSFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM