简体   繁体   中英

Put Rally.ui.chart.Chart charts inside a container

I'm trying to put two Rally charts inside a container to have a control over their layout. Unfortunately, for some reason, it doesn't work. Plase see the code (the full HTML provided for convinience):

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0rc3/sdk.js"></script>

<script type="text/javascript">
    Rally.onReady(function () {
            Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',

_atTheStartAddedChart: null,
_stateChart: null,

launch: function () {
    //Write app code here
    var me = this;

    me._createAtTheStartAddedChart();
    me._createStateChart();

    console.log('chart 1', me._atTheStartAddedChart);
    console.log('chart 2', me._stateChart);

    me._chartContainer = Ext.create('Ext.Container', {
        itemId: 'cont',
        renderTo: Ext.getBody(),
        layout: {
            type: 'hbox',
            align: 'middle'
        }
        ,
        items: [
            me._atTheStartAddedChart,
            me._stateChart
        ]
    });
    me.add(me._chartContainer);
},

_createAtTheStartAddedChart: function () {
    var me = this;

    var series = [
        {
            type: 'pie',
            name: 'Features',
            data: [
                {
                    name: 'At the Start',
                    y: 20,
                    color: '#0CDBE8'
                },
                {
                    name: 'Added During Release',
                    y: 30,
                    color: '#FFE11A'
                }
            ]
        }
    ];

    var chart = me._createChart(series);
    me._atTheStartAddedChart = chart;
},

_createStateChart: function () {
    var me = this;

    var series = [
        {
            type: 'pie',
            name: 'Features',
            data: [
                {
                    name: 'Not Completed in Time',
                    y: 10,
                    color: '#FFE11A'
                },
                {
                    name: 'Completed in Time',
                    y: 15,
                    color: '#98C000'
                },
                {
                    name: 'Removed from Release',
                    y: 20,
                    color: '#EA2E49'
                },
                {
                    name: 'Completely Removed',
                    y: 5,
                    color: '#3D4C53'
                }
            ]
        }
    ];

    var chart = me._createChart(series);
    me._stateChart = chart;
},

_createChart: function (series) {
    var chart = Ext.create('Rally.ui.chart.Chart', {
        chartConfig: {
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Release Features'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.y}</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: false,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            }
        },
        chartData: {
            series: series
        }
    });

    return chart;
}
});


        Rally.launchApp('CustomApp', {
            name:"Random App Name42726",
            parentRepos:""
        });

    });
</script>
</head>
<body>
</body>
</html>

The charts are created successfully, but they are not displayed at all. There is no error related to their display, so I don't even know where to look for the issue. Maybe someone knows how to put the charts horizontally (I don't really need Ext.Container here, any other container will be fine as well)?

There is also an error Uncaught Highcharts error #16: www.highcharts.com/errors/16 (Highcharts already defined in the page), not sure what's the reason for it as well.

I made those charts display - you may see full app and the screenshot showing both pie charts in this repo .

Here is the js file. The main change was where in the code the chart was added to container. I moved that to _createChart function. Highchart error 16 does not prevent the charts from loading. You may eventually create two containers and add the charts to separate containers, but this works in its simplest form:

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    _atTheStartAddedChart: null,
    _stateChart: null,
    items: [
        {
            xtype: 'container',
            itemId: 'mychart',
            columnWidth: 1
        }
    ],
    launch: function() {

        this._createAtTheStartAddedChart();
        this._createStateChart();
    },

    _createAtTheStartAddedChart: function () {

    var series = [
        {
            type: 'pie',
            name: 'Features',
            data: [
                {
                    name: 'At the Start',
                    y: 20,
                    color: '#0CDBE8'
                },
                {
                    name: 'Added During Release',
                    y: 30,
                    color: '#FFE11A'
                }
            ]
        }
    ];
    this._createChart(series);
},

    _createStateChart: function () {
        var me = this;

        var series = [
            {
                type: 'pie',
                name: 'Features',
                data: [
                    {
                        name: 'Not Completed in Time',
                        y: 10,
                        color: '#FFE11A'
                    },
                    {
                        name: 'Completed in Time',
                        y: 15,
                        color: '#98C000'
                    },
                    {
                        name: 'Removed from Release',
                        y: 20,
                        color: '#EA2E49'
                    },
                    {
                        name: 'Completely Removed',
                        y: 5,
                        color: '#3D4C53'
                    }
                ]
            }
        ];
        this._createChart(series);
},

    _createChart: function (series) {
        var chartDiv = this.down("#mychart");
        chartDiv.add({
            xtype: 'rallychart',
            chartConfig: {
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                title: {
                    text: 'Release Features'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.y}</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: false,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: false
                        },
                        showInLegend: true
                    }
                }
            },
            chartData: {
                series: series
            }
        });
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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