2013-06-21 13 views
5

Sto cercando di rimuovere le etichette di graduazione dell'asse y da un grafico a barre discreto in nvd3.nvd3: rimuovere le etichette di graduazione sull'asse y dal grafico a barre discreto

Ho già esaminato la fonte di nvd3, ma non riesco a trovare una funzione ovvia che potrei cambiare. Qualcuno può indicarmi la soluzione?

Aggiornamento: Codice

function Transform(value1, value2, chart_name,value3) { 
value3 = typeof value3 !== 'undefined' ? value3 : 'no_header'; 
var chart = nv.models.discreteBarChart() 
    .x(function (d) { 
    return d.label; 
}) 

    .y(function (d) { 
    return d.value; 
}) 

    .staggerLabels(true) 
    .tooltips(false) 
    .showValues(true); 

var a = []; 
var f = [{ 
    values: [] 
}]; 
d3.csv("../../csv/master.csv").get(function (error, rows) { 

if (error){ 
    console.log(error); 
    loadError("Uh Oh. This data set is missing... Try going <a href='/'>back to the start</a>"); 
    return; 
    } 

    for (var i = 0; i < rows.length; i++) { 
     a.push(rows[i]); 
    } 
    console.log(a[0].agency); 
    for (var key = 0; key < a.length; key++) { 
     var b = a[key]; 
     for (var c in b) { 
      if (c != "agency" && c != "division" && c != "pod") { 
       var d = b[c]; 
       a[key][c] = +d; 
      } 
     } 
     console.log(a[0].changes); 
     } 
    try { 
    var e = $.grep(a, function (v) { 
     return v.division == {{division|safe}}; 
     }); 
    var k = $.grep(e, function(v) { 
     return v.agency == {{agency|safe}}; 
     })[0]; 
    console.log(k.division); 
     } 
    catch (TypeError) { loadError("Uh Oh. We could not find this combination\ 
     of Agency & Division. Try going back to the <a href='/pitchview'>selection menu</a>"); 
    return; 
    } 
    if (k.agency){ 
    for (var g in k) { 
     if (g == value1 || g == value2 || g == value3) { 
      var h = { 
       "label": g, 
        "value": k[g] 
      }; 
      f[0].values.push(h); 
     } 
    } 


    d3.select('#' + chart_name + ' svg') 
     .datum(f) 
     .transition().duration(500) 
     .call(chart) 
    nv.utils.windowResize(chart.update); 
    return chart; 
    } else { 
    loadError("Uh Oh. We could not find this combination of Agency &\ 
     Division. Try going back to the <a href='/pitchview'>selection menu</a>");}}); 
} 
+0

Avete provato qualcosa di simile 'chart.yAxis.ticks (0)'? –

+0

Sì, l'ho provato, dopo l'opzione dei suggerimenti, ma non ha funzionato. Questa è la posizione sbagliata? – jvdh

+0

Questa sarebbe una riga di codice separata, non un'opzione da impostare. –

risposta

20

C'è una variabile nella nvd3 bar-funzione discreta che rimuove l'asse y (incluse le etichette). Utilizza questo nel codice di rimuoverli: esiste

.showYAxis(false) 

Una variabile simile per l'asse x.

+0

Questa dovrebbe essere la risposta accettata! Quello sopra è più di un trucco! –

3

uso chart.yAxis.tickValues ​​(0), si spegnerà le yticks e mantenere l'etichetta y

+0

Ottima risposta ~ Plus 1! – Miron

Problemi correlati