简体   繁体   English

条形图的日期范围选择器

[英]Date range selector for barchart

I want to implement Date Range selector for my barchart, below is the some of the code I wrote. 我想为我的条形图实现日期范围选择器,以下是我编写的一些代码。 I am showing stacked bar chart, it should dynamically update according to date range selected. 我正在显示堆积的条形图,它应根据所选的日期范围动态更新。 Any suggestions on this. 任何建议。 Thanks in advance 提前致谢

            _onDataLoadedfirst: function() {
                Ext.create('Ext.panel.Panel', {
                    title: 'Choose a future date:',
                    width: 200,
                    bodyPadding: 10,
                    renderTo: Ext.getBody(),
                    items: [{
                        xtype: 'datepicker',
                        minDate: new Date(),
                        handler: function(picker, date) {
                            // do something with the selected date
                        }
                    }]
                });         
            },  
            _onDataLoaded: function(store, data) {
                this.add(
                    {
                        xtype: 'rallychart',                                
                        height: new_height,
                        //width: 500,
                        series: [
                            {
                                type: 'bar',
                                dataIndex: 'ObjectCount',
                                name: 'Count',
                                visible: true
                            }
                        ],
                        //store: severityStore,
                        calculatorType: 'My.TrendCalc',
                        calculatorConfig : {},
                        chartConfig: {
                            chart: {
                                    zoomType: 'xy',
                                    type:'bar'
                            },
                            title: {
                                text: ' Open Defects(per Team and Severity)',
                                //align: 'center'
                            },
                            legend: {
                                reversed: true
                            },
                            //xField: 'Project',
                            xAxis: {
                                categories: new_projects,
                                type: 'text',
                                title: { text: 'Teams'},
                                minTickInterval: 5,
                                //labels : { rotation: 90 }
                            },
                            //yField: 'Severity',
                            yAxis: { 
                                min: 0,
                                //categories: teamGroups,
                                title: {
                                    text: 'Quantity of Defects'
                                }
                            },                                  
                            plotOptions: {
                                area: {
                                    stacking: 'percent',
                                    lineColor: 'black',
                                    lineWidth: 1,
                                    marker: {
                                        enabled: false
                                    },
                                    step: true,
                                    size: '100%'
                                },  
                                bar: {
                                    borderColor: "#000000",
                                    borderWidth: 0.2
                                },  
                                series: {
                                    stacking: 'normal',
                                    dataLabels: {
                                        enabled: true,
                                        color: 'white',
                                        align: 'center',
                                        x: 2,
                                        y: 5,                                           
                                        formatter:function(){
                                            if(this.y > 0)
                                                return this.y;
                                        },                                              
                                        style: {
                                            textShadow: '0 0 2px black, 0 0 2px black'
                                        }
                                    }
                                }
                            },
                        },      
                            //categories: teamGroups, 
                        series: [{  
                            name: "None",
                            data: get_values(proj_records, 0),
                            color: "#7CAED5"
                        },{
                            name: "Critical",
                            data: get_values(proj_records, 1),
                            color: "#66dacf"
                        },{
                            name: "Major",
                            data: get_values(proj_records, 2),
                            color: "#87c540"
                        },{ 
                            name: "Minor",
                            data: get_values(proj_records, 3),
                            color: "#9863b2"
                        },{                             
                            //Ext.Array.each(proj_records[0], function(rec) {
                            name: "Incidental",
                            data: get_values(proj_records, 4),
                            color: "#d73249"
                                //data: record.data;
                            //});
                        }]
                    }
                );
             }

Here is an example of a chart of Open/Closed defects that reloads with new data when a anther date is selected in the date picker. 这是打开/关闭缺陷图表的示例,当在日期选择器中选择花药日期时,该图表会重新加载新数据。 You will need to change metrics object to reflect allowed values in the State dropdown in your environment. 您将需要更改metrics对象,以反映环境中“状态”下拉列表中允许的值。

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    launch: function() {
        var that = this;
        var minDate = new Date(new Date() - 86400000*90); //milliseconds in day = 86400000
        var datePicker = Ext.create('Ext.panel.Panel', {
            title: 'Choose a date:',
            width: 200,
            bodyPadding: 10,
            renderTo: Ext.getBody(),
            items: [{
                xtype: 'rallydatepicker',
                minDate: minDate,
                handler: function(picker, date) {
                     that.onDateSelected(date);
                }
            }]
        });        
        this.add(datePicker);
    },
    onDateSelected:function(date){
        this._date = date;
        this.defineCalculator();
        this.makeChart();
   },    

    defineCalculator: function(){
        var that = this;
        Ext.define("MyDefectCalculator", { 
            extend: "Rally.data.lookback.calculator.TimeSeriesCalculator",
            getMetrics: function () {
                var metrics = [
                   {
                        field: "State",
                        as: "Open",
                        display: "column",
                        f: "filteredCount",
                        filterField: "State",
                        filterValues: ["Submitted","Open"]
                   },
                    {
                        field: "State",
                        as: "Closed",
                        display: "column",
                        f: "filteredCount",
                        filterField: "State",
                        filterValues: ["Fixed","Closed"]
                    }
                ];  
                return metrics;
            }
        });
    },

    makeChart: function(){
        if (this.down('#myChart')) {
                this.remove('myChart');
        }
        var timePeriod = new Date(new Date() - this._date);

        var project = this.getContext().getProject().ObjectID;

        var storeConfig = this.createStoreConfig(project,timePeriod);

        this.chartConfig.calculatorConfig.startDate = this._date;
        this.chartConfig.calculatorConfig.endDate = new Date();
        this.chartConfig.storeConfig = storeConfig;
        this.add(this.chartConfig); 
    },

    createStoreConfig : function(project, validFrom ) {
        return {
            listeners : { 
                load : function(store,data) {
                    console.log("data",data.length);
                }
            },
            filters: [
                {
                    property: '_ProjectHierarchy',
                    operator : 'in',
                    value : [project] 
                },
                {
                    property: '_TypeHierarchy',
                    operator: 'in',
                    value: ['Defect']
                },
                {
                    property: '_ValidFrom',
                    operator: '>',
                    value: validFrom
                }
            ],
            autoLoad : true,
            limit: Infinity,
            fetch: ['State'],
            hydrate: ['State']
        };
    },
     chartConfig: {
        xtype: 'rallychart',
        itemId : 'myChart',
        chartColors: ['Red', 'Green'],

        storeConfig: { },
        calculatorType: 'MyDefectCalculator',

        calculatorConfig: {
        },

        chartConfig: {

            plotOptions: {
                column: { stacking: 'normal'}
            },
            chart: { },
            title: { text: 'Open/Closed Defects' },
            xAxis: {
                tickInterval: 1,
                labels: {
                    formatter: function() {
                        var d = new Date(this.value);
                        return ""+(d.getMonth()+1)+"/"+d.getDate();
                    }
                },
                title: {
                    text: 'Date'
                }
            },
            yAxis: [
                {
                    title: {
                        text: 'Count'
                    }
                }
            ]
            }
    }   

});

The example is in this github repo . 这个例子在这个github repo中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM