Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your first example doesn't work because Meteor calls your helper functions as it figures out what to render. At that point your chart template doesn't yet exist in the DOM.</p> <p>Your second example doesn't work because of a scope problem. You're trying to use a variable in the rendered handler that only exists in init.</p> <p>This should work:</p> <pre><code>Template.chart.rendered = function() { $('#chart').highcharts(myCollection.find()); }; </code></pre> <hr> <p>If you need to do calculated values, there are a couple of ways to approach it. </p> <p><strong>Approach #1: Change the collection on the client</strong></p> <p>Pros: easy and fast to develop</p> <p>Cons: client browser has to do the calculation, which - depending on the collection size and the calculation - could be slow</p> <p>Example:</p> <pre><code>var dataWithCalculations = _.map(myCollection.find(), function(document) { document.someValue = document.someOtherValue * 2; return document; }); $('#chart').highcharts(dataWithCalculations); </code></pre> <p>I'm not sure if this approach is reactive or not. If it's not, it should be easy to fix by using a <a href="http://docs.meteor.com/#deps" rel="nofollow">dependency</a>.</p> <p><strong>Approach #2: Use a transform</strong></p> <p>Pros: easy and fast to develop</p> <p>Cons: not reactive</p> <p>Example: </p> <pre><code>Forms = new Meteor.Collection("forms", { transform: function(document) { document.someValue = document.someOtherValue * 2; return document; } }); </code></pre> <p><strong>Approach #3: Use a custom publication</strong></p> <p>Pros: Reactive, calculation run on the server</p> <p>Cons: Not easy or straightforward</p> <p>Example: Check the count-by-rooms <a href="http://docs.meteor.com/#meteor_publish" rel="nofollow">example</a> in the Meteor documentation</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload