简体   繁体   English

带有chart.js的angularjs中的响应图

[英]Responsive charts in angularjs with chart.js

im trying to make a responsive chart js, as the title say. 我正在尝试制作一个响应式图表js,如标题所示。 I use a framework from charts.js from here. 我从这里使用Charts.js中的框架。 http://jtblin.github.io/angular-chart.js/ . http://jtblin.github.io/angular-chart.js/ I'm new on angular so the concepts of the framework are vague to me. 我对angular还是陌生的,所以框架的概念对我来说很模糊。

I want to make the canvas to have the same size like the div which contains it, doesnt matter if the chart will be disproportionated. 我想使画布具有与包含它的div相同的大小,如果图表将不成比例都没关系。 If you can help me... for now I working with first example from the site. 如果您可以帮助我...目前,我正在使用该站点的第一个示例。

<canvas id="line" class="chart chart-line" chart-data="data"
chart-labels="labels" chart-series="series" chart-options="options"
chart-dataset-override="datasetOverride" chart-click="onClick">
</canvas>

Javascript code JavaScript代码

angular.module("app", ["chart.js"]).controller("LineCtrl", function ($scope) {

$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
  [65, 59, 80, 81, 56, 55, 40],
  [28, 48, 40, 19, 86, 27, 90]
];
$scope.onClick = function (points, evt) {
  console.log(points, evt);
};
$scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
$scope.options = {
  scales: {
    yAxes: [
      {
        id: 'y-axis-1',
        type: 'linear',
        display: true,
        position: 'left'
      },
      {
        id: 'y-axis-2',
        type: 'linear',
        display: true,
        position: 'right'
      }
    ]
  }
};
});

You can try extending your $scope.options with 您可以尝试使用扩展$scope.options

responsive: true,
maintainAspectRatio: false

take a look at the docs chart.js responsive docs 看看docs chart.js响应式文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM