<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multiple Timeline graphs on a single webpage Javascript SDK in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Multiple-Timeline-graphs-on-a-single-webpage-Javascript-SDK/m-p/79650#M1141</link>
    <description>&lt;P&gt;Not sure if this is the best way to go about this ... but I got it to work by creating a second spunk.ui.timeline.js file and calling it in the second script which then generates the second timeline graph successfully.&lt;/P&gt;

&lt;P&gt;Updated this line to point to the second version of spunk.ui.timeline:&lt;/P&gt;

&lt;P&gt;var timelineToken = splunkjs.UI.loadTimeline("/client/splunk.ui.timeline2.js", function() {&lt;/P&gt;</description>
    <pubDate>Sat, 29 Jun 2013 02:52:31 GMT</pubDate>
    <dc:creator>jenks22222</dc:creator>
    <dc:date>2013-06-29T02:52:31Z</dc:date>
    <item>
      <title>Multiple Timeline graphs on a single webpage Javascript SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Multiple-Timeline-graphs-on-a-single-webpage-Javascript-SDK/m-p/79649#M1140</link>
      <description>&lt;P&gt;I am attempting to display multiple timeline graphs on the same webpage via the JavaScript SDK.  The first graph shows up, but the second one does not.  In firebug, I can see both jobs get created, but only div id timeline-container0 is populated by a timeline graph.  I wasn't sure if I am overwriting a variable or there is some type of race condition going on..... any insight would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Code:&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;META charset="utf-8" /&gt;&lt;BR /&gt;
    &lt;TITLE&gt;How to start a Splunk session&lt;/TITLE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;link href="/examples/browser/resources/bootstrap.css" rel="stylesheet"&amp;gt;
&amp;lt;link href="/examples/browser/resources/prettify.css" type="text/css" rel="stylesheet" /&amp;gt;
&amp;lt;link href="/examples/browser/resources/timeline.css" type="text/css" rel="stylesheet" /&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H1&gt;timeline-container0 {&lt;/H1&gt;

&lt;P&gt;height: 250px;&lt;BR /&gt;
width: 500px;&lt;BR /&gt;
}&lt;/P&gt;

&lt;H1&gt;timeline-container1 {&lt;/H1&gt;

&lt;P&gt;height: 250px;&lt;BR /&gt;
width: 500px;&lt;BR /&gt;
}&lt;BR /&gt;
    &lt;BR /&gt;
    &lt;SCRIPT type="text/javascript" src="https://community.splunk.com/client/splunk.js"&gt;&lt;/SCRIPT&gt;&lt;BR /&gt;
    &lt;SCRIPT type="text/javascript" src="https://community.splunk.com/examples/browser/resources/jquery.min.js"&gt;&lt;/SCRIPT&gt;&lt;BR /&gt;
    &lt;SCRIPT type="text/javascript" charset="utf-8"&gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;var http = new splunkjs.ProxyHttp(&amp;amp;quot;/proxy&amp;amp;quot;);&amp;lt;br&amp;gt;
svc = new splunkjs.Service(http, {&amp;lt;br&amp;gt;
scheme: &amp;amp;quot;https&amp;amp;quot;,&amp;lt;br&amp;gt;
host: &amp;amp;quot;xxx&amp;amp;quot;,&amp;lt;br&amp;gt;
port: &amp;amp;quot;8089&amp;amp;quot;,&amp;lt;br&amp;gt;
username: &amp;amp;quot;xxx&amp;amp;quot;,&amp;lt;br&amp;gt;
password: &amp;amp;quot;xxx&amp;amp;quot;,&amp;lt;br&amp;gt;
});&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Async = splunkjs.Async;&amp;lt;br&amp;gt;
utils = splunkjs.Utils; &amp;lt;br&amp;gt;
var timeline = null;&amp;lt;br&amp;gt;
var timelineToken = splunkjs.UI.loadTimeline(&amp;amp;quot;/client/splunk.ui.timeline.js&amp;amp;quot;, function() {&amp;lt;br&amp;gt;
// Once we have the charting code, create a chart.&amp;lt;br&amp;gt;
timeline = new splunkjs.UI.Timeline.Timeline($(&amp;amp;quot;#timeline-container0&amp;amp;quot;));&amp;lt;br&amp;gt;
});&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;var searchTerm = &amp;amp;#39;search index=_internal | head 10000 | stats count(host), count(source) by sourcetype&amp;amp;#39;;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;// A small utility function to queue up operations on the chart&amp;lt;br&amp;gt;
// until it is ready.&amp;lt;br&amp;gt;
var updateTimeline = function(data) {&amp;lt;br&amp;gt;
var setData = function() {&amp;lt;br&amp;gt;
timeline.updateWithJSON(data);&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
if (timeline === null) {&amp;lt;br&amp;gt;
splunkjs.UI.ready(timelineToken, function() { setData(); });&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
else {&amp;lt;br&amp;gt;
setData();&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
};&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Async.chain([&amp;lt;br&amp;gt;
// Login&amp;lt;br&amp;gt;
function(callback) { svc.login(callback); },&amp;lt;br&amp;gt;
// Create the job&amp;lt;br&amp;gt;
function(success, callback) {&amp;lt;br&amp;gt;
svc.jobs().create(searchTerm, {status_buckets: 300}, callback);&amp;lt;br&amp;gt;
},&amp;lt;br&amp;gt;
// Loop until the job is &amp;amp;quot;done&amp;amp;quot;&amp;lt;br&amp;gt;
function(job, callback) {&amp;lt;br&amp;gt;
job.track({}, {&amp;lt;br&amp;gt;
// Queue up timeline displays while we are querying the job&amp;lt;br&amp;gt;
progress: function(job) {&amp;lt;br&amp;gt;
job.timeline({}, function(err, data) {&amp;lt;br&amp;gt;
if (!err) updateTimeline(data);&amp;lt;br&amp;gt;
});&amp;lt;br&amp;gt;
},&amp;lt;br&amp;gt;
// Move forward once the search is done&amp;lt;br&amp;gt;
done: function(job) {&amp;lt;br&amp;gt;
callback(null, job);&amp;lt;br&amp;gt;
},&amp;lt;br&amp;gt;
error: function(err) {&amp;lt;br&amp;gt;
callback(err);&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
});&amp;lt;br&amp;gt;
},&amp;lt;br&amp;gt;
// Get the final timeline data&amp;lt;br&amp;gt;
function(job, callback) {&amp;lt;br&amp;gt;
job.timeline({}, callback);&amp;lt;br&amp;gt;
},&amp;lt;br&amp;gt;
// Update the timeline control&amp;lt;br&amp;gt;
function(timelineData, job, callback) {&amp;lt;br&amp;gt;
updateTimeline(timelineData);&amp;lt;br&amp;gt;
callback(null, job);&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
],&amp;lt;br&amp;gt;
// And we&amp;amp;#39;re done, so make sure we had no error, and&amp;lt;br&amp;gt;
// cancel the job&amp;lt;br&amp;gt;
function(err, job) {&amp;lt;br&amp;gt;
if (err) {&amp;lt;br&amp;gt;
console.log(err);&amp;lt;br&amp;gt;
alert(&amp;amp;quot;An error occurred&amp;amp;quot;);&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
if (job) {&amp;lt;br&amp;gt;
job.cancel();&amp;lt;br&amp;gt;
}&amp;lt;br&amp;gt;
});&amp;lt;br&amp;gt;
&lt;/SCRIPT&gt;&lt;/P&gt;

&lt;SCRIPT type="text/javascript" charset="utf-8"&gt;

var http1 = new splunkjs.ProxyHttp("/proxy");
svc1 = new splunkjs.Service(http1, {
scheme: "https",
host: "xxx",
port: "8089",
username: "xxx",
password: "xxx",
});



Async1 = splunkjs.Async;
utils1 = splunkjs.Utils; 
var timeline1 = null;
var timelineToken1 = splunkjs.UI.loadTimeline("/client/splunk.ui.timeline.js", function() {
// Once we have the charting code, create a chart.
timeline1 = new splunkjs.UI.Timeline.Timeline($("#timeline-container1"));
});
 
var searchTerm1 = 'search index=_internal | head 10000 | stats count(host), count(source) by sourcetype';

 
// A small utility function to queue up operations on the chart
// until it is ready.
var updateTimeline1 = function(data1) {
var setData1 = function() {
timeline1.updateWithJSON(data1);
}
if (timeline1 === null) {
splunkjs.UI.ready(timelineToken1, function() { setData1(); });
}
else {
setData1();
}
};
 
Async1.chain([
// Login
function(callback) { svc1.login(callback); },
// Create the job
function(success, callback) {
svc1.jobs().create(searchTerm1, {status_buckets: 300}, callback);
},
// Loop until the job is "done"
function(job1, callback) {
job1.track({}, {
// Queue up timeline displays while we are querying the job
progress: function(job1) {
job1.timeline({}, function(err, data1) {
if (!err) updateTimeline1(data1);
});
},
// Move forward once the search is done
done: function(job1) {
callback(null, job1);
},
error: function(err) {
callback(err);
}
});
},
// Get the final timeline data
function(job1, callback) {
job1.timeline({}, callback);
},
// Update the timeline control
function(timelineData1, job1, callback) {
updateTimeline1(timelineData1);
callback(null, job1);
}
],
// And we're done, so make sure we had no error, and
// cancel the job
function(err, job1) {
if (err) {
console.log(err);
alert("An error occurred");
}
if (job1) {
job1.cancel();
}
});
&lt;/SCRIPT&gt;

&lt;P&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;/P&gt;&lt;H2&gt;Timeline Graph 1&lt;/H2&gt;&lt;BR /&gt;
&lt;DIV id="timeline-container0"&gt;&lt;BR /&gt;
    &lt;/DIV&gt;&lt;BR /&gt;
&lt;H2&gt;Timeline Graph 2&lt;/H2&gt;&lt;BR /&gt;
&lt;DIV id="timeline-container1"&gt;&lt;BR /&gt;
    &lt;/DIV&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2013 18:14:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Multiple-Timeline-graphs-on-a-single-webpage-Javascript-SDK/m-p/79649#M1140</guid>
      <dc:creator>jenks22222</dc:creator>
      <dc:date>2013-06-28T18:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Timeline graphs on a single webpage Javascript SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Multiple-Timeline-graphs-on-a-single-webpage-Javascript-SDK/m-p/79650#M1141</link>
      <description>&lt;P&gt;Not sure if this is the best way to go about this ... but I got it to work by creating a second spunk.ui.timeline.js file and calling it in the second script which then generates the second timeline graph successfully.&lt;/P&gt;

&lt;P&gt;Updated this line to point to the second version of spunk.ui.timeline:&lt;/P&gt;

&lt;P&gt;var timelineToken = splunkjs.UI.loadTimeline("/client/splunk.ui.timeline2.js", function() {&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2013 02:52:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Multiple-Timeline-graphs-on-a-single-webpage-Javascript-SDK/m-p/79650#M1141</guid>
      <dc:creator>jenks22222</dc:creator>
      <dc:date>2013-06-29T02:52:31Z</dc:date>
    </item>
  </channel>
</rss>

