rCharts nvd3 library force ticks

后端 未结 1 466
失恋的感觉
失恋的感觉 2021-01-06 02:16

I would like to force all tick marks and tick labels to appear along the axis in an rCharts nPlot from the nvd3 library. I have tried several appro

相关标签:
1条回答
  • 2021-01-06 02:55

    It turns out I was not correctly setting tickValues as I got the syntax confused with tickFormat. Here is an rCharts solution. The corresponding d3 or nvd3 solution should be easy to deduce.

    n <- nPlot(data = df, y ~ x, type = 'lineChart')
    n$yAxis(showMaxMin = FALSE)
    n$addParams(height = 500, width = 1000)
    n$xAxis(tickValues = "#! function (x) {    
        tickvalues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
        return tickvalues;
    } !#")
    n$xAxis(tickFormat = "#! function (x) {
        tickformat = ['0-1000', '1000-1500', '1500-1700', '1700-1820', '1820-1913', 
           '1913-1950', '1950-1970', '1970-1990', '1990-2012', '2012-2030', '2030-2050', 
           '2050-2070', '2070-2100'];
        return tickformat[x-1];
    } !#")
    n
    

    Notice how the code has tickvalues in tickValues but tickformat[x-1] in tickFormat.

    enter image description here

    0 讨论(0)
提交回复
热议问题