添加预测到Dygraph

时间:2017-02-27 18:48:19

标签: r dygraphs

我正在关注以下教程:

https://rstudio.github.io/dygraphs/

他们在底部显示预测,我想将其添加到原始时间序列图表中。以下是代码,我不知道如何将两者结合起来:

$string = '<abc>A1</abc><bcd>B1</bcd><abc>A2</abc><bcd>B2</bcd><abc>A3</abc>';
$take = explode('<abc>', $string);
foreach ($take as $value) {
$take = explode('</abc>',$value);
 echo "<pre>";
 print_r($take);
}

enter image description here

然后我做了一个预测:

install.packages("dygraphs")
library(dygraphs)
library(forecast)
library(dplyr)

dygraph(ldeaths)

enter image description here

如何将两者合并为一个图形?

1 个答案:

答案 0 :(得分:2)

似乎这个库需要你组合数据,然后在图中添加单独的系列“图层”。通过您的示例,您可以执行此操作:

var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json";

url += '?' + $.param({
'api-key' : "67dac4e994164fca920f7a8420e28dc2",
'q' : "health"

});

$.ajax({
url: url,
method: 'GET',
success : function(result){

var articles = result.response.docs;

for(var i=0; i<articles.length; i++){
    $("h2").each(function(index, el){
        $(el).html(articles[index].headline.main);
    });

    $(".article--snippet").each(function(index, el){
        $(el).html(articles[index].snippet);
    });

    $(".post").each(function(index, el){
        $("el").css("background", "url(" + articles[index].thumbnail +")");
    });

    // console.log(articles[i].url);

    $(".linked--headline").each(function(index, el){
        $(el).attr("href", articles[index].web_url);    
    });

    /// Your thumbnails:
    for (var i=0;i<r.response.docs.length;i++)
    {
          var thumbUrl = r.response.docs[i].multimedia.filter(function(el){ return el.subtype='thumbnail'})[0].url;
    // e.g: thumbUrl = 'images/2017/02/28/science/28BRODY/28BRODY-thumbWide.jpg'

    }
    // console.log(articles[i].web_url);
}
}).fail(function(err){
  throw err;
});

enter image description here