Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom label for x axis on nvd3 graphs
    primarykey
    data
    text
    <p>I am fairly new to graphs using javascript and started using d3 and nvd3 for a project now. I am trying to plot a multi bar chart provided by nvd3 module. I am successful in plotting the data however, I am not able to customize the values for x axis for each series. I believe it is taking integer values for x to plot the graph. My question is how can I show some custom value like X, Y, Z instead of 1, 2, 3 for each graph. </p> <p>Below is my code i am using</p> <pre><code>var data = [{ "key" : "Step 1", "values" : [{"y" : 5,"x" : 2,},{"y" : 4,"x" : 1,}, {"y" : 4,"x" : 0,}] }, { "key" : "Step 2", "values" : [{"y" : 4,"x" : 0}, {"y" : 5,"x" : 2 }, {"y" : 6,"x" : 1 }] }, { "key" : "Step 3", "values" : [{"y" : 5,"x" : 2}, {"y" : 4,"x" : 0 }, {"y" : 5,"x" : 1 }] }]; var chart; var tickValues = ['X','Y','Z']; nv.addGraph(function() { chart = nv.models.multiBarChart().margin({ bottom : 100 }).transitionDuration(300).delay(0).groupSpacing(0.5); chart.multibar.hideable(true); chart.reduceXTicks(true).staggerLabels(true); chart.xAxis.showMaxMin(false) //.tickValues(tickMarks) .tickFormat(function(x){ return tickValues[x] } ); chart.yAxis.tickFormat(d3.format(',.1f')); d3.select('#chart1 svg').datum(data).call(chart); nv.utils.windowResize(chart.update); return chart; }); </code></pre> <p>if i plot the graph using the above code, the graph is generating properly but the Custom Values for X axis are completely out of order. I want X to be printed where value in data array hss x = 0, Y for data array x = 1 and so on. But right now its coming randomly.</p> <p>I tried passing the data as </p> <pre><code>var data = [{ "key" : "Step 1", "values" : [{"y" : 5,"x" : "Z",},{"y" : 4,"x" : "Y",}, {"y" : 4,"x" : "X",}] </code></pre> <p>So that I can plot the desired value of each axis as mention in data, but it does not work. :(</p> <p>Is there a better way to keep the values in sync ? Any help is highly appreciable. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload