相关疑难解决方法(0)

如何在angular-chart.js中为每个条设置不同的颜色?

我看过如何更改Angular-Chart.js的颜色,但它与整个(数据集)的颜色有关,而不是特定的栏.

我正在寻找的是一种在条形图中为每个条形应用不同颜色的方法; ChartJS到Angular.

所以,我有一个条形图:

<canvas id="locationBar" class="chart chart-bar" data="chartParams.votes" labels="chartParams.listOfLocations" series="chartParams.series" colours="chartParams.colours" options="chartParams.options"></canvas> 
Run Code Online (Sandbox Code Playgroud)

使用以下角度代码(当然在控制器中)

$scope.chartParams = {
    listOfLocations: ['Trenzalore','Earth','Caprica','Sol','Tau Ceti'],
    votes: [[5,10,6,7,2]],
    series: ["Nice Places"],
    colours: [{fillColor:getRandomColour()}],
    options: {barShowStroke : false}
};
Run Code Online (Sandbox Code Playgroud)

哪里getRandomColour()会返回一个随机颜色.

现在,该colours字段将此颜色应用于所有条形:

相同的颜色:( 不同的颜色

当我真的想要每个酒吧有不同的颜色时:

Plunker

javascript charts bar-chart angularjs

13
推荐指数
2
解决办法
2万
查看次数

angular-chartjs条形图中每列的颜色不同

我正在我正在进行的项目中使用angular-chartJS,并且我需要为条形图中的每个条形图使用不同的颜色.

帆布:

<canvas id="bar" class="chart chart-bar" data="medal_data" labels="medal_ticks"></canvas>
Run Code Online (Sandbox Code Playgroud)

控制器:

$scope.medal_ticks = ['Gold', 'Silver', 'Bronze', 'Not passed'];
$scope.series = ['Medaljer'];
$scope.medals_colours= ['#087D76', '#B3BC3A', '#38B665', '#8B4A9D'];

$scope.medal_data = ['1', '5', '2', '0'];
Run Code Online (Sandbox Code Playgroud)

我试图将属性添加colours="medals_colours"到我的画布,唯一的问题是它只使用数组中的第一种颜色,我想要的是每种颜色代表每一列.所以,#087D76用于表示Gold,#B3BC3ASilver

javascript bar-chart angularjs chart.js angular-chart

7
推荐指数
1
解决办法
3860
查看次数

使用ng-repeat {ANGULAR.JS}加载JSON以显示数据

我的Html:

<div class="graph-display" ng-controller="jsonServerBox">
    <div class="bar-chart-box" ng-repeat="module in ocw.modules"> 
        <canvas class="chart chart-bar" data="{{module.data}}" labels="{{module.labels}}" series="{{module.series}}"></canvas>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我的JS:

app.controller('jsonServerBox', function($scope, $http) {
  var json = $http.get('serverbox.json').then(function(res){
          return res.data;
        });
  $scope.ocw = json;    
    });
Run Code Online (Sandbox Code Playgroud)

图表没有显示,不知道为什么?我也没有在控制台中出现任何错误.

更新:我的JSON文件内容

[{"modules":[
            {
               "series":"SeriesA",
               "data":["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"],
               "labels":["01", "02", "03", "04", "05", "06", "07","08","09","10"]
            },

            {
               "series":"SeriesB",
               "data":["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"],
               "labels":["01", "02", "03", "04", "05", "06", "07","08","09","10"]
            }

    ]}
]
Run Code Online (Sandbox Code Playgroud)

控制台日志:

modules: …
Run Code Online (Sandbox Code Playgroud)

angularjs chart.js

6
推荐指数
1
解决办法
1万
查看次数

我想更改所选的每个城市或子城市的图表

我用AngularJS开发了一个简单的应用程序,我想基于这个网站Js Charts添加一个简单的图表

这是我的data.json:

[
    {
        "name": "city A",
        "elements": [
            {
                "id": "c01",
                "name": "name1",
                "price": "15",
                "qte": "10"
            },
            {
                "id": "c02",
                "name": "name2",
                "price": "18",
                "qte": "11"
            },
            {
                "id": "c03",
                "name": "name3",
                "price": "11",
                "qte": "14"
            }
        ],
        "subsities": [
            {
                "name": "sub A1",
                "elements": [
                    {
                        "id": "sub01",
                        "name": "nameSub1",
                        "price": "1",
                        "qte": "14"
                    },
                    {
                        "id": "sub02",
                        "name": "nameSub2",
                        "price": "8",
                        "qte": "13"
                    },
                    {
                        "id": "sub03",
                        "name": "nameSub3",
                        "price": "1", …
Run Code Online (Sandbox Code Playgroud)

javascript charts angularjs zingchart

4
推荐指数
1
解决办法
1329
查看次数