NVD3 - Changing the axis of the X mark on a line graph

I have a simple line graph with data in the format:

[
    {
        label: "lebel1",
        x: 0,
        y: 128
    },
    {
        label: "lebel1",
        x: 1,
        y: 128
    },
    ....
    {
        label: "lebel2",
        x: 25,
        y: 128
    },
    ....
    {
        label: "lebel8",
        x: 285,
        y: 128
    },
    .... 

}

and I pass this to my nvd3 object:

nv.addGraph(function() 
{
    var chart = nv.models.lineChart();

    chart.xAxis
        .axisLabel("My X-Axis")
        .ticks(36)
        .tickFormat(function(d) { return d; });

    chart.yAxis
        .axisLabel('Voltage (v)')
        .tickFormat(d3.format('.02f'));

    d3.select('div svg')
        .datum(myData)
        .transition().duration(500)
        .call(chart);

    nv.utils.windowResize(function() { d3.select(gridSvgId).call(chart) });

    return chart;
});

How can I show my checkmarks along the x axis: * eight labels: label1 - label8

Instead of having the lattices split into a variable number of rows?

+4
source share
1 answer

Try something like this

chart.xAxis.tickValues(['Label 1','Label 2','Label 3','Label 4','Label 5','Label 6','Label 7','Label 8']);

or if you want to get it from a dataset, you can try something like this,

chart.xAxis.tickValues(function(d) {
    // do all you stuff and return an array
    var dataset = ['Build Array from data'];

    return dataset;
};)

Hope this helps

+3
source

All Articles