highcharts-datalet.html 2.05 KB
<link rel="import" href="../base-ajax-json-jsonpath-datalet/base-ajax-json-jsonpath-datalet.html">

<dom-module id="highcharts-datalet">

    <template>
        <div id="container" style="width:auto; height:auto;"></div>
        <base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}"></base-ajax-json-jsonpath-datalet>
    </template>

    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>

    <script>
        var HighchartsBehavior = {

            properties: {

                categories: {
                    type: Array,
                    value: []
                },

                series: {
                    type: Array,
                    value: []
                },

                series_type:{
                    type: String,
                    value: "line"//spline,time
                }
            },

            selectData: function () {

                this.properties.categories.value = this.data[0].data;

                for (var i = 1; i < this.data.length; i++)
                {

                    this.data[i].data.every(function (element, index, array) {
                        try {
                            (isNaN(parseFloat(element))) ? array[index] = parseFloat(element.match(/[0-9]+/g).join(".")) :
                                    array[index] = parseFloat(element);
                        }catch(e){
                            //console.log("Parsing data error. Highchart-datalet.selectData");
                        }
                        return true;
                    });

                    this.properties.series.value.push(this.data[i]);
                }
            }
        };

        var HighchartsComponentBehavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, HighchartsBehavior);

        HighchartsDatalet = Polymer({
            is : 'highcharts-datalet'
        });
    </script>

</dom-module>