Guillaume
Guillaume

Reputation: 1

Stacked Graph - AmChart - JavaScript

I've created an AmChart which is supposed to show stacked aeras. I don't know why, everything goes fine except the graphs aren't stacked...

Here's the code:


 var JSONChart = {
        "type":"serial",
        "backgroundAlpha":1,
        "backgroundColor":"white",
        "autoMargin":true,"autoMarginOffset":30,
        "marginRight":50,
        "creditsPosition":"bottom-right",
        "titles":"TEST",
        "fontSize":15,
        "categoryAxis": {"parseDates":true,"minPeriod":"ss","axisAlpha":1,"gridAlpha":"white",},
        "chartScrollbar":{"enabled":true,"backgroundAlpha":1},
        "dataProvider":Tableau,
        "categoryField":"Date",
        "ValueAxis":[{"stackType":"regular","axisAlpha":0,"gridAlpha":0.1,"unit":"MWh","unitPosition":"left"}],
        "chartCursor":{"cursorColor":"red","valueLineBalloonEnabled":true,"valueLineEnabled":true,"valueZoomable":true},
        }

        var Graphiques =  [];
        for (var j=1;j<TableFinale[0].length;j++){
            var Param = {};
            Param.id = "g"+j.toString();
            Param.type = "line";
            Param.lineColor = "red";
            Param.valueField = j.toString();
            Param.fillAlphas = 0.3;
            Graphiques.push(Param);
        }
        JSONChart.graphs=Graphiques;

        customVisualzationObject = AmCharts.makeChart("chartdiv",JSONChart );

do you have an idea why the "regular" value of the Stacktype property doesn't apply?

Thanks


I changed the spelling, here's the code now:

    evar JSONChart = {
        "type":"serial",
        "ValueAxes": [{"stackType":"regular","axisAlpha":0,"gridAlpha":0.1,"unit":"MWh","unitPosition":"left"}],
        "backgroundAlpha":1,
        "backgroundColor":"white",
        "autoMargin":true,"autoMarginOffset":30,
        "marginRight":50,
        "creditsPosition":"bottom-right",
        "titles":"TEST",
        "fontSize":15,
        "categoryAxis": {"parseDates":true,"minPeriod":"mm","axisAlpha":1,"gridAlpha":"white"},
        "chartScrollbar":{"enabled":true,"backgroundAlpha":1},
        "dataProvider":Tableau,
        "categoryField":"Date",
        "chartCursor":{"cursorColor":"blue","valueLineBalloonEnabled":true,"valueLineEnabled":true,"valueZoomable":true},
        "Legend":{"position":"top","valueTextRegular":"bite","valueWidth":100},
        "export": {
        "enabled": true, "position":"bottom-right" }
        }

        var Graphiques =  [];
        for (var j=1;j<TableFinale[0].length;j++){
            var Param = {};
            Param.id = "g"+j.toString();
            Param.type = "line";
            Param.lineColor = getRandomColor();
            Param.valueField = j.toString();
            Param.fillAlphas = 0.3;
            Graphiques.push(Param);
        }
        JSONChart.graphs=Graphiques;

The final chart is still not stacked... I don't know why. The legend is not working too though.

Here's is the dataprovider table I'm using:
enter image description here

I really don't understand what's wrong in my JSON. Thanks for you help

Upvotes: 0

Views: 106

Answers (1)

vpa2
vpa2

Reputation: 186

I think the problem is due the misspelled variable name:

  • In your JSONChart object try to change the attribute name from "ValueAxis" to "ValueAxes" instead.

Ref:

Upvotes: 1

Related Questions