2014-04-17 178 views
1

我已經分配了一個在圖中顯示兩個圖表的任務,因此我需要兩個y軸來表示圖表。 單軸將位於左側,另一個位於右側。AmChart沒有顯示第二個y軸

我的問題是隻有一個y軸顯示。 當我使用amCharts時,我注意到一個問題,其中可見的y軸有一個名爲allLabels的數組,其中有元素,但第二個y軸沒有,但我不知道 是什麼填充數組屬性。

代碼:

function addconsumerUsageGraph(consumerUsageGraph) { 
//You can ignore this 
    if (consumerUsageGraph.graphs.length == 2) 
    { 
     var gr1 = consumerUsageGraph.graphs[0]; 
     var gr2 = consumerUsageGraph.graphs[1]; 
     consumerUsageGraph.removeGraph(gr1); 
     consumerUsageGraph.removeGraph(gr2); 
    } 

    if (consumerUsageGraph.graphs.length == 1) { 
     var gr1 = consumerUsageGraph.graphs[0]; 
     consumerUsageGraph.removeGraph(gr1); 
    } 

    //I add the two yAxis here: 
    var yAxis1 = new AmCharts.ValueAxis(); 
    yAxis1.position = "left"; 

    var yAxis2 = new AmCharts.ValueAxis(); 
    yAxis2.position = "right"; // set this to "right" if you want it on the right 

    //Adding the value axis to the whole graph 
    consumerUsageGraph.addValueAxis(yAxis1); 
    consumerUsageGraph.addValueAxis(yAxis2); 

    var graph = new AmCharts.AmGraph(); 
    graph.valueField = "value"; 
    graph.type = "column"; 
    graph.title = "Usage"; 
    graph.lineAlpha = 1; 
    graph.fillAlphas = 0.75; 

    consumerUsageGraph.addGraph(graph); 

    var graph2 = new AmCharts.AmGraph(); 
    graph2.valueField = "cost"; 
    graph2.type = "line"; 
    graph2.lineAlpha = 1; 
    graph2.title = "Cost"; 
    graph2.lineColor = graphColour; 
    graph2.bullet = "round"; 
    graph2.bulletAlpha = 0.5; 
    graph2.bulletBorderAlpha = 0.8; 

    //Assigning the second yAxis to the second graph 
    graph2.valueAxes = yAxis2; 


    consumerUsageGraph.addGraph(graph2); 

    //consumerUsageGraph.write("chartdiv"); 

    var legend = new AmCharts.AmLegend(); 
    legend.marginBottom = -10; 
    legend.useGraphSettings = true; 
    consumerUsageGraph.addLegend(legend); 
    } 

如何圖表現在看起來:

enter image description here

回答

3

圖形不具有財產valueAxes,使用valueAxis代替:

graph2.valueAxis = yAxis2;