Dygraph with R - 如何使用axisLabelFormatter作为标签的字符大小?

时间:2016-07-18 06:29:19

标签: r axis-labels dygraphs

我是R中Dygraph的新手,我用来绘制我的数据(用xts)。一切都很好,效果很好。

但问题是:我无法使用var eventBind == false if ($(window).width() <= 640 && eventBind == false) { // now bind your event here. eventBind = true; } 来制作大胆且更大的标签。怎么可能?

此外,我可以在图表周围添加一个框架(如x和y轴的黑线)?

此处的图片解释了我的两个问题:click here for example image

以下是我正在尝试的代码:

axisLabelFormatter

2 个答案:

答案 0 :(得分:1)

试试这个:

    dyAxis(
      "y",
      axisLabelFormatter = 'function(d){return d.toString().fontsize(4);}', #     makes them bigger
      axisLabelWidth = 70
    ) %>%
and change the fontsize(4) to other numbers. An for bold tage the line: axisLabelFormatter = 'function(d){return d.toString().fontsize(4).bold();}',
as:

    dygraph(Temperature,main="Evolution de la tempértaure") %>%
        dyAxis("y", label = "°C ", valueRange = c(-1, 11)) %>%
        dySeries("..1",label="MC1_Temp",strokeWidth=1.75) %>%
        dySeries("..2",label="MC2_Temp",strokeWidth=1.75) %>%
        dySeries("..3",label="MC3_Temp",pointSize=2.5) %>%
        dySeries("..4",label="MC4_Temp",pointSize=2.5) %>%
        dyOptions(colors = c("blue","orange","pink","green")) %>%
        dyLegend(width=400) %>%
        dyEvent(DebutVidange, "Ouverture Vanne de Fond", labelLoc = "top") %>%
        dyEvent(FinVidange, "Fin Vidange", labelLoc = "top") %>%
        dyShading(from =DebutVidange, to =FinVidange, color = "#F0F9FF") %>%
        dyShading(from =DebutAssec, to =FinAssec, color = "#FFFFFF") %>%
    dyAxis(
      "y",
      axisLabelFormatter = 'function(d){return d.toString().fontsize(4);}', # makes them bigger
      axisLabelWidth = 70
    ) %>%
        dyRangeSelector()

答案 1 :(得分:-1)

我也得到了x轴,但是它会变成数字:2017.3等等,请注意你需要添加1到几个月,因为JDE中Jan-Dec的月份是0-11,这里:

   dyAxis(
  "x",
  # label = "Number",
  axisLabelFormatter = 'function(d){ var month = (d.getMonth() +1).toString().fontsize(3) ;var year = d.getFullYear().toString().fontsize(3); return  year + "."+ month}', ## + 1 since months jan-dec are 0-11 in Javascript
  axisLabelFontSize = 20,
  axisLabelWidth = 70 ## gets them apart, but not bigger
) %>%