简体   繁体   English

具有2个Y轴的ExtJS柱形图

[英]ExtJS Column Chart with 2 Y axes

I'm trying to plot a column chart with 2 series and thus 2 Y axis, one in the left side and the other in the right side. 我正在尝试绘制一个包含2个系列的列图,也就是2个Y轴,一个在左侧,另一个在右侧。 But the columns display in the same place, on top of each others and not side by side. 但是这些列显示在同一位置,彼此重叠,而不是并排显示。 Do you have any idea how to fix this ? 您有解决的办法吗?

Something like that : 像这样:

Ext.onReady(function () {
    var chart;


    chart = new Ext.chart.Chart({
        width: 800,
        height: 600,
        animate: true,
        store: store1,
        renderTo: Ext.getBody(),
        shadow: true,
        axes: [{
            type: 'Numeric',
            position: 'left',
            fields: ['data1'],
            label: {
                renderer: Ext.util.Format.numberRenderer('0,0')
            },
            title: 'Number of Hits',
            grid: true,
            minimum: 0
        }, {
            type: 'Category',
            position: 'bottom',
            fields: ['name'],
            title: 'Month of the Year'
        }, {
            type: 'Numeric',
            position: 'right',
            fields: ['data2'],
            title: 'Test'
        }],
        series: [{
            type: 'column',
            axis: 'left',
            highlight: true,
            xField: 'name',
            yField: 'data1'
        }, {
            type: 'column',
            axis: 'right',
            xField: 'name',
            yField: 'data2'
        }]
    });
});

Thanks 谢谢

Create a zero value entry into the store and append it to the first and second series items. 在商店中创建一个零值条目,并将其附加到第一和第二系列项目。 The number of additions depends on the length of series yField items of the other axes. 加法数取决于其他轴的yField系列项目的长度。

For example, creating two series items having yField respectively as below: 例如,创建两个分别具有yField的系列项目,如下所示:

yField: ['data1', 'data2','data4']

and

yField: ['data4','data4','data3']

where data4 is a zero value entry in the store. 其中data4是商店中的零值条目。

The solution worked perfectly. 该解决方案运行完美。 :) :)

This will add two columns for the left axis and a third one for the right axis: 这将为左轴添加两列,为右轴添加第三列:

series: [{
    type: 'column',
    axis: 'left',
    highlight: true,
    label: {
        field: ['data1']
    },
    xField: ‘name’,
    yField: ['data1', 'data2','whateverUndefinedFieldNameYouComeUpWith'] // Use an undefined field
},{
    type: 'column',
    axis: 'right',
    highlight: true,
    label: {
        field: 'data3′
    },
    xField: 'name',
    yField: ['name','name','data3'] // or just use the same field you use for the x axis
}]

I hope you get the idea. 希望您能明白。

AFAIK, you cannot have them side-by-side. AFAIK,您不能将它们并排放置。 The reason is they are not in the same series. 原因是它们不在同一系列中。 When you have two data in same series, they get displayed side-by-side. 当您有两个相同系列的数据时,它们会并排显示。 In your case, you have two series.. one configured to use the left axis and other the right. 在您的情况下,您有两个系列。一个配置为使用左轴,另一个配置为使用右轴。 I suggest you use a different type of chart for one of your series. 我建议您对系列之一使用其他类型的图表。

series: [{
    type: 'line', // Instead of column chart I am using line chart...
    axis: 'left',
    highlight: true,
    xField: 'name',
    yField: 'data1'
}, {
    type: 'column',
    axis: 'right',
    xField: 'name',
    yField: 'data2'
}]

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

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