带线形图的Amcharts堆积柱形图将valueaxis置于线形图之下

时间:2019-02-05 04:56:45

标签: javascript angularjs line amcharts stacked

我准备了一个图表,其中堆积柱形图与折线图相结合。现在,堆叠图表的总值,即值轴应该在堆叠列上。但是总价值超过折线图。 没有折线图,它是完美的。 enter image description here 但是使用折线图,总价值上升。 enter image description here 这是我的代码

$scope.chart = AmCharts.makeChart("chartdiv", {
        "type": "serial",
        "theme": "none",
        "legend": {
            "position": "top",
            "useGraphSettings": true,
            "align": "center"
        },
        "dataProvider": $scope.monthly_chart_data,
        "valueAxes": [{
            "stackType": "regular",
            "axisAlpha": 0.3,
            "gridAlpha": 0,
            "totalText": "[[total]]"
        }],
        "graphs": [{
            "balloonText": "<span style='font-size:14px'><b>[[value]]</b></span>",
            "fillAlphas": 0.8,
            "lineAlpha": 0.0,
            "title": "Betrag",
            "type": "column",
            "color": "#000000",
            "valueField": "Rechnung",
            "fillColors": "#003d6a"
        }, {
            "balloonText": "<span style='font-size:14px'><b>[[value]]</b></span>",
            "fillAlphas": 0.8,
            "lineAlpha": 0.0,
            "title": "Bestellung",
            "type": "column",
            "color": "#000000",
            "valueField": "Bestellung",
            "fillColors": "#8673a4"
        }, {
            "id": "graph2",
            "lineThickness": 1.5,
            "fillAlphas": 0,
            "lineAlpha": 1,
            "lineColor": "#e95f30",
            "title": "Budget",
            "valueField": "Budget",
            "dashLengthField": "dashLengthLine",
            "stackable": false
        }],
        "categoryField": "month",
        "categoryAxis": {
            "gridPosition": "start",
            "axisAlpha": 0,
            "gridAlpha": 0,
            "position": "left"
        },
        "numberFormatter" : {
            "precision": -1,
            "decimalSeparator": ",",
            "thousandsSeparator": "."
        }
    });

如何将总值(即valueaxis)放在堆积的列上,但在折线图之下?任何帮助,将不胜感激。提前致谢。

1 个答案:

答案 0 :(得分:1)

您的线轴被添加到同一堆栈中; stacked适用于整个值轴及其关联的所有图形,而不仅仅是特定的图形或类型,因此该行也包含在堆栈和总计中。如果您不希望将行包含在堆栈及其总数中,只需将其分配给其他值轴即可。

    "synchronizeGrid": true, //optional if you want both axes to have the same scale. Doesn't always work, though.
    "valueAxes": [{
        "stackType": "regular",
        "axisAlpha": 0.3,
        "gridAlpha": 0,
        "totalText": "[[total]]"
    },{
        "id": "valueAxis2",  //create second axis for the line graph
        "axisAlpha": 0,
        "position": "right",
        "gridAlpha": 0
    }],
    "graphs": [
     // ...
     {
        "id": "graph2",
        "valueAxis": "valueAxis2", //assign line graph to valueAxis2
        "lineThickness": 1.5,
        "fillAlphas": 0,
        "lineAlpha": 1,
        "lineColor": "#e95f30",
        "title": "Budget",
        "valueField": "Budget",
        "dashLengthField": "dashLengthLine",
        "stackable": false
    }]