Adding multiple value axis to a Stock Charts panel

Martynas Majeris -

In Stock chart, each stock panel is an instance of AmSerialChart. So you can add ValueAxis pbjects to it like you would normally add to a regular chart.

Each StockGraph is an instance os AmGraph so it has "valueAxis" property.

So adding multiple value axes to a stock panel is just like adding them to a regular basic serial chart. I.e.:

    // adding stock panel
    var stockPanel1 = new AmCharts.StockPanel();
    stockPanel1.title = "Value";
    
    // add value axes
    var valueAxis1 = new AmCharts.ValueAxis();
    stockPanel1.addValueAxis(valueAxis1);
    
    var valueAxis2 = new AmCharts.ValueAxis();
    valueAxis2.position = "right";
    stockPanel1.addValueAxis(valueAxis2);

    // graph #1
    var graph1 = new AmCharts.StockGraph();
    graph1.valueField = "value";
    graph1.lineThickness = 3;
    graph1.lineColor = "#00cc00";
    graph1.useDataSetColors = false;
    stockPanel1.addStockGraph(graph1);

    // graph #2
    var graph2 = new AmCharts.StockGraph();
    graph2.valueField = "volume";
    graph2.type = "column";
    graph2.showBalloon = false;
    graph2.fillAlphas = 0.5;
    graph2.valueAxis = valueAxis2;
    stockPanel1.addStockGraph(graph2);

    // set panels to the chart
    chart.panels = [stockPanel1];

 

That's it. Now you have two graphs, one attached to left value axis, the other to the right one.

Here's a working demo: http://jsfiddle.net/amcharts/CuhgM/

Have more questions? Submit a request

Comments

  • Avatar
    Danny Jackson

    Would you mind posting an example of how to do this using the JSON format?

     

    Thanks :)

Powered by Zendesk