2014-04-17 1 views
1

그래프에 2 개의 차트를 표시하는 작업이 할당되었으므로 차트를 나타 내기 위해 두 개의 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

그래프는 valueAxis를 사용하여 속성 valueAxes이없는 대신 :

graph2.valueAxis = yAxis2;