HighCharts和Handlebars

时间:2015-05-28 02:22:09

标签: jquery highcharts handlebars.js

在编译期间是否可以将Highcharts图表注入Handlebars模板?我似乎无法获得注入图表的元素。我通常可以做$('#value-graph').highcharts(options);之类的事情,但这里似乎没有用。有没有人有过这方面的成功,还是手把不可能?

var data = {
  name: 'This',
  address: '1141 Rd'
};
var source = $('#company-template').html(); // not sure if this is the selector name
var template = Handlebars.compile(source);

var content = template(data);
Handlebars.registerHelper('drawGraph', function() {
  var options = {
    chart: {
      height: 160
    },
    title: {
      text: null
    },
    legend: {
      enabled: false
    }
  };

  options.xAxis.categories = ["Nov '13", "Dec '13"];
  options.series = [{
    data: [100, 50];
  }];

  $('#value-graph').highcharts(options);
});
script#company-template(type='text/x-handlebars-template').
  <section class="header">
    <h3>{{name}}</h3>
    <div class="address">{{address}}</div>
  </section>
  <section class="details">
    <div class="graph" id="value-graph">{{drawGraph}}</div>
  </section>

0 个答案:

没有答案