我试图在条形图中显示Y和Y2但在y2轴上它在c3.js中仅显示范围内的0到1值

时间:2017-04-04 07:45:39

标签: javascript c# c3.js

我正在为列和数据1,数据2生成动态名称。现在,我尝试在条形图中显示YY2但在y2轴中仅显示0 js

范围内的1c3
$(document).ready(function () { 
    var FunnelGrowthACVColumns = [];
    var FunnelGrowthRatioColumns = [];

    for (var i = 0; i <= data.data.FunnelGrowthMartix.length - 1; i++) {
        FunnelGrowthACVColumns.push(parseFloat(data.data.FunnelGrowthMartix[i].FunnelGrowth));
        FunnelGrowthRatioColumns.push(parseFloat(data.data.FunnelGrowthMartix[i].Per_Growth));
    }

    var titleFunnelGrowthACV = data.data.FunnelGrowthMartix[0].Title + 'ACV';
    var titleFunnelGrowthRatio = data.data.FunnelGrowthMartix[0].Title +'Ratio';

    var chart1 = c3.generate({
        bindto: '#chartContainer2',
        data: {
            columns: [                               
                [titleFunnelGrowthACV].concat(FunnelGrowthACVColumns),                               
                [titleFunnelGrowthRatio].concat(FunnelGrowthRatioColumns),
            ],
            type: 'bar',
            labels: true,
            axes: {
                titleFunnelGrowthACV: 'y',
                titleFunnelGrowthRatio: 'y2'
            },
        },
        axis: {
            x: {
                type: 'category',
                categories: MartixMonths,
            },
            y: {
                label: {
                    text: 'Unit (In Rs Crores)',
                    position: 'outer-middle'
                },
            },
            y2: {
                show: true,
            }
        },
        color: {
            pattern: ['#2ca02c', '#0000ff']
        },
        zoom: {
            enabled: false
        },
        bar: {
            width: {
                ratio: 0.5
            },
            tooltip: {
                format: {
                    title: function (d) { return 'Data' + d; },
                },
                grouped: true
            },
            legend: {
                position: 'center'
            }
        }
    });
    $('#chartContainer2').append(chart1.element);
});

数据1和数据2的y轴值都在变化。

data2_graph data1_graph data1&data2_graph

1 个答案:

答案 0 :(得分:0)

第二个y轴的范围0..1往往在一个系列尚未绑定时发生。

查看截图我怀疑你刚收到错字。屏幕截图中的工具提示显示系列名称“FunnelGrowthACV”和“FunnelGrowthRatio”,但您要求

axes: {
        titleFunnelGrowthACV: 'y',
        titleFunnelGrowthRatio: 'y2'
}, 

将其更改为

axes: {
        FunnelGrowthACV: 'y',
        FunnelGrowthRatio: 'y2'
}, 

并查看现在是否有效