Angular-google-area-chart 图表背景颜色重叠

Angular-google-area-chart chart background color overlapping

提问人:the_mishra 提问时间:9/28/2017 最后编辑:Towkirthe_mishra 更新时间:4/14/2022 访问量:579

问:

enter image description here

我正在使用 .我正在尝试为特定区域显示不同的颜色。但是你可以看到红线和绿线(区域)的区域与蓝色区域重叠。 配置有问题吗?angular-google-chart

"data": {
    "cols": [{
        "id": "date",
        "label": "Date",
        "type": "string",
        "p": {}
    }, {
        "id": 'sd0',
        "label": 'sdo',
        "type": "number",
        "p": {}
    }, {
        "id": 'sd1',
        "label": 'sd1',
        "type": "number",
        "p": {}
    }, {
        "id": 'sd2',
        "label": 'sd2',
        "type": "number",
        "p": {}
    }, {
        "id": 'sd3',
        "label": 'sd3',
        "type": "number",
        "p": {}
    }, {
        "id": 'sd1Neg',
        "label": 'sd1Neg',
        "type": "number",
        "p": {}
    }, {
        "id": 'sd2Neg',
        "label": 'sd2Neg',
        "type": "number",
        "p": {}
    }, {
        "id": 'sd3Neg',
        "label": 'sd3Neg',
        "type": "number",
        "p": {}
    }],
    "rows": $scope.dataMap
},
"options": {
    "isStacked": "false",
    'displayAnnotations': true,
    'legend': {
        'position': 'bottom'
    },

    "fill": 20,
    "displayExactValues": true,
    "vAxis": {
        "title": 'Weight'
    },
    "hAxis": {
        "title": "Age",
        "slantedText": false,
        /* Enable slantedText for horizontal axis */
        // "slantedTextAngle": 90
    },
    'chartArea': {
        'width': '82%',
        'height': '70%',
        'top': '15%',
        'left': '15%',
        'right': '3%',
        'bottom': '30%'
    },
    'pointSize': 2,
    'annotation': {
        'alwaysOutside': true,
        'textStyle': {
            'fontSize': 17,
            'auraColor': '#eee',
            'annotationsWidth': 25,
            'color': '#eee'
        }
    },
    'series': {
        0: { areaOpacity: 1},
        1: { areaOpacity: 1},
        2: { areaOpacity: 1},
        3: { areaOpacity: 1},
        4: { areaOpacity: 1},
        5: { areaOpacity: 1},
        6: { areaOpacity: 1}
    },
    'colors': ['#FF0000','#FF0000','#00FF00','#0000FF','#00FF00','#0000FF','#FFFFFF']
},

在我从数组推送数据中:$scope.dataMap

for(var i=0;i<$scope.data.sd0.length;i++){
    $scope.dataMap.push({
        c: [{
            v: $scope.gData.sd0[i].month
        }, {
            v: $scope.gData.sd0[i].value
        }, {
            v: $scope.gData.sd1[i].value
        }, {
            v: $scope.gData.sd2[i].value
        }, {
            v: $scope.gData.sd3[i].value
        }, {
            v: $scope.gData.sd1Neg[i].value
        }, {
            v: $scope.gData.sd2Neg[i].value
        }, {
            v: $scope.gData.sd3Neg[i].value
        }]
    });
}

$scope.gData是我从发布请求中获取的对象,包含值数组。有 7 个值数组,JSON 结构都是一样的

"sd0": [
    {
        "month": "0",
        "value": "2.1"
    },
    {
        "month": "1",
        "value": "2.9"
    },
    {
        "month": "2",
        "value": "3.8"
    },
    {
        "month": "3",
        "value": "4.4"
    }
    .....
]
javascript css angularjs google-visualization

评论

0赞 the_mishra 9/28/2017
我想要特定图表区域的唯一颜色,上图中绘制的图表按顺序排列 sd3,sd2,sd1,sd0,sd1neg,sd2neg,sd3neg,颜色数组中的颜色代码按代码中定义的顺序排列,即 sd0,sd1,sd2,sd3,sd1neg,sd2neg,sd3neg。data
0赞 WhiteHat 10/4/2017
在 colors 数组中,你有 3 种颜色,每种颜色使用两次,最后一种是白色——如果你想要独特的颜色,需要使用 7 种不同的颜色,白色系列甚至显示吗?-- 只是想了解颜色的使用是故意的,还是问题的一部分......
0赞 the_mishra 10/9/2017
我正在努力实现这样的事情,bcm.edu/bodycomplab/Images/Flash/BMIexpl.png
0赞 the_mishra 10/9/2017
突出显示两个特定值之间的区域,根据我在面积图中使用颜色。
1赞 Lakmi 10/10/2017
你能把你的代码放到 JSFIDDLE 中吗?

答:

0赞 Nikhil 4/14/2022 #1
**HTML**
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   <div id="chart_div" style="width: 100%; height: 500px;"></div>


**js**

      google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses'],
      ['2013',  1000,      400],
      ['2014',  1170,      460],
      ['2015',  660,       1120],
      ['2016',  1030,      540]
    ]);

    var options = {
      title: 'Company Performance',
      hAxis: {title: 'Year',  titleTextStyle: {color: '#333'}},
      vAxis: {minValue: 0}
    };

    var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  }
0赞 Selaka Nanayakkara 12/15/2023 #2

google.charts.load('current', {
  'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Sales', 'Expenses'],
    ['2013', 1000, 400],
    ['2014', 1170, 460],
    ['2015', 660, 1120],
    ['2016', 1030, 540]
  ]);

  var options = {
    title: 'Company Performance',
    hAxis: {
      title: 'Year',
      titleTextStyle: {
        color: '#333'
      }
    },
    vAxis: {
      minValue: 0
    }
  };

  var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
  chart.draw(data, options);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<div id="chart_div" style="width: 100%; height: 500px;"></div>