Подтвердить что ты не робот

RCharts-Как добавить осевые таблицы и заголовки в диаграмму NVD3

Я развожу rCharts. Я застрял, добавляя Lables к оси Y и заголовкам. Я новичок в rCharts.

Это мой пример кода

require(rCharts)
n2 <- nPlot(Hours ~ Month, group = "Task", data = cars, type = "multiBarChart",
height = 900, width = 1110)
n2$xAxis(axisLabel = 'Year and Month')
n2

Пожалуйста, помогите.

4b9b3361

Ответ 1

ответ, дополненный примерами заголовков 2013-12-05

Я не помню, почему nvd3 с rCharts делает это, но мы обнаружили это в этом issue. Метод, предложенный в этой проблеме, работает, но использование margin является, вероятно, более надежным методом. Я привел пример из двух способов. Дайте мне знать, как это работает.

      require(rCharts)

      df <- data.frame(x=1:20,y=runif(n=20))

      n1 <- nPlot(
        y~x,
        data=df,
        type="multiBarChart"
      )
      n1$yAxis( axisLabel = "Randomness" )

      #nvd3 draws the label but falls outside the bounds
      #so two ways to fix

      #best way I believe is to set the margin to allow room
      #nvd3 draws at -63, so something bigger than 63
      n1$chart(margin = list(left = 100))
      n1


      #second way as discussed here
      #https://github.com/ramnathv/rCharts/issues/102
      n1$yAxis( axisLabel = "Randomness", width = 40 )
      n1

теперь добавьте заголовок

Есть несколько способов добиться этого. В настоящее время я предпочитаю использовать шаблон script с rCharts. Вот два примера. Элемент <h3> вставляется в div rCharts. Два шаблона живут в этом репо, если вы хотите посмотреть, как они работают.

      #for a local template something like this
      #n1$templates$script <- "./chartWithTitle.html"
      n1$templates$script <- "http://timelyportfolio.github.io/rCharts_nvd3_templates/chartWithTitle.html"
      n1$set(title = "rCharts + nvd3 Power")
      n1

      #using some css style from http://tympanus.net/codrops/2012/11/02/heading-set-styling-with-css/
      #put in a different template 
      n1$templates$script <- "http://timelyportfolio.github.io/rCharts_nvd3_templates/chartWithTitle_styled.html"
      n1