简体   繁体   English

将Rally.ui.chart.Chart图表放入容器中

[英]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. 我试图将两个Rally图表放入一个容器中,以控制其布局。 Unfortunately, for some reason, it doesn't work. 不幸的是,由于某种原因,它不起作用。 Plase see the code (the full HTML provided for convinience): 请查看代码(为方便起见提供了完整的HTML):

<!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)? 也许有人知道如何水平放置图表(我这里真的不需要Ext.Container,也可以使用其他任何容器)?

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. 还有一个错误Uncaught Highcharts错误#16:www.highcharts.com/errors/16(该页面已定义了Highcharts),也不知道是什么原因。

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. 这是js文件。 The main change was where in the code the chart was added to container. 主要更改是在代码中将图表添加到容器的位置。 I moved that to _createChart function. 我将其移至_createChart函数。 Highchart error 16 does not prevent the charts from loading. Highchart错误16不会阻止图表加载。 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
            }
        });
    }
});

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

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