How to integrate amcharts and Ember.js?

I am trying to integrate ember.js and amcharts. I've created following view based on code from live chart editor (http://pastebin.com/XWVWkhJk)

App.AmchartView = Ember.View.extend
    classNames: ['amcharts']
    series: []
    config: {}

    didInsertElement: ->
        @renderGraph()

    renderGraph: (->
        AmCharts.makeChart @get('elementId'),
            type: "serial"
            pathToImages: "http://cdn.amcharts.com/lib/3/images/"
            categoryField: "date"
            dataDateFormat: "YYYY-MM-DD"
            categoryAxis:
                parseDates: true
            chartCursor: {}
            chartScrollbar: {}
            trendLines: []
            graphs: [
                {
                    bullet: "round"
                    id: "AmGraph-1"
                    title: "graph 1"
                    valueField: "column-1"
                }
                {
                    bullet: "square"
                    id: "AmGraph-2"
                    title: "graph 2"
                    valueField: "column-2"
                }
            ]
            guides: []
            valueAxes: [
                id: "ValueAxis-1"
                title: "Axis title"
            ]
            allLabels: []
            balloon: {}
            legend:
                useGraphSettings: true

            titles: [
                id: "Title-1"
                size: 15
                text: "Chart Title"
            ]
            dataProvider: [
                {
                    date: "2014-03-01"
                    "column-1": 8
                    "column-2": 5
                }
                {
                    date: "2014-03-02"
                    "column-1": 6
                    "column-2": 7
                }
                {
                    date: "2014-03-03"
                    "column-1": 2
                    "column-2": 3
                }
                {
                    date: "2014-03-04"
                    "column-1": 1
                    "column-2": 3
                }
                {
                    date: "2014-03-05"
                    "column-1": 2
                    "column-2": 1
                }
                {
                    date: "2014-03-06"
                    "column-1": 3
                    "column-2": 2
                }
                {
                    date: "2014-03-07"
                    "column-1": 6
                    "column-2": 8
                }
            ]
    ).observes('series', 'config')

Inside the view I can see amcharts divs but graph is not rendering. What's wrong? I have all the amcharts files included in <link> tag and there is not any error in browser console.


There are a few things you might be missing here. If you included a jsbin or jsfiddle instead of just the view file, it would be much easier to guess what might be going wrong.

For one thing, I don't know what your template file looks like, so I don't know how you're injecting this chart.

I've been able to successfully make an amchart using an Ember view in this jsbin.

If you can post more of your code, I'd be happy to help isolate what's going wrong, I know SO is supposed to be more showing the why than the how, but there just isn't enough info here.

链接地址: http://www.djcxy.com/p/61938.html

上一篇: Cordova Jquery Mobile本地通知onclick更改页面

下一篇: 如何整合amcharts和Ember.js?