• <bdo id='Wvhjj'></bdo><ul id='Wvhjj'></ul>
  • <legend id='Wvhjj'><style id='Wvhjj'><dir id='Wvhjj'><q id='Wvhjj'></q></dir></style></legend>
  • <small id='Wvhjj'></small><noframes id='Wvhjj'>

      <tfoot id='Wvhjj'></tfoot>
        <i id='Wvhjj'><tr id='Wvhjj'><dt id='Wvhjj'><q id='Wvhjj'><span id='Wvhjj'><b id='Wvhjj'><form id='Wvhjj'><ins id='Wvhjj'></ins><ul id='Wvhjj'></ul><sub id='Wvhjj'></sub></form><legend id='Wvhjj'></legend><bdo id='Wvhjj'><pre id='Wvhjj'><center id='Wvhjj'></center></pre></bdo></b><th id='Wvhjj'></th></span></q></dt></tr></i><div id='Wvhjj'><tfoot id='Wvhjj'></tfoot><dl id='Wvhjj'><fieldset id='Wvhjj'></fieldset></dl></div>

        Ng2-Charts Linechart 仅显示前 2 个两个值

        Ng2-Charts Linechart only showing first 2 two values(Ng2-Charts Linechart 仅显示前 2 个两个值)

            <tfoot id='4b0hQ'></tfoot>
            • <legend id='4b0hQ'><style id='4b0hQ'><dir id='4b0hQ'><q id='4b0hQ'></q></dir></style></legend>

                <tbody id='4b0hQ'></tbody>

                <small id='4b0hQ'></small><noframes id='4b0hQ'>

                <i id='4b0hQ'><tr id='4b0hQ'><dt id='4b0hQ'><q id='4b0hQ'><span id='4b0hQ'><b id='4b0hQ'><form id='4b0hQ'><ins id='4b0hQ'></ins><ul id='4b0hQ'></ul><sub id='4b0hQ'></sub></form><legend id='4b0hQ'></legend><bdo id='4b0hQ'><pre id='4b0hQ'><center id='4b0hQ'></center></pre></bdo></b><th id='4b0hQ'></th></span></q></dt></tr></i><div id='4b0hQ'><tfoot id='4b0hQ'></tfoot><dl id='4b0hQ'><fieldset id='4b0hQ'></fieldset></dl></div>
                  <bdo id='4b0hQ'></bdo><ul id='4b0hQ'></ul>
                  本文介绍了Ng2-Charts Linechart 仅显示前 2 个两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在启动使用 Angular-CLI(beta 22.1)初始化的新 Angular 应用程序.但是,当我在图表中添加测试数据(5 个值)时,它似乎缩放错误,只显示前两个值并将它们拉伸到整个图表长度(见图).

                  该项目是空白的,并且不包含任何 CSS.

                  我的app.component.html:

                  app.component.ts

                  从'@angular/core'导入{组件};从ng2-charts/ng2-charts"导入{ BaseChartDirective };@零件({选择器:'应用程序根',templateUrl: './app.component.html',styleUrls: ['./app.component.css']})导出类 AppComponent {私人号码:任何[] = [{标签:测试",data: [10,2,6,7]//应该在图表中造成 4 个点}];私人_chartOpt:任何= {响应式:真};公共 _chartColours:any[] = [];私有_标签:字符串[] = [];私人_chartLegend:布尔=假;私人 _chartType: string = "line";}

                  chart.js 库是通过 angular-cli.json 添加的:

                  脚本":[../node_modules/chart.js/dist/Chart.bundle.min.js"],

                  我真的不知道我哪里错了.我尝试了许多不同的选项(responsive: true/falsemaintainAspectRatio : true/false、将 <canvas> 包装在 ><div> 并且没有,CSS 样式,宽度/高度属性,...),但似乎无法让这个工作.我什至将 ng2-charts 版本降级为我曾经使用过的版本,但没有运气.

                  如果您需要更多代码,请告诉我.

                  解决方案

                  labels 属性必须与值一起定义.根据 properties 的文档:

                  <块引用>

                  labels (?Array) - x 轴标签.图表是必需的:折线、条形和雷达.

                  因此,为标签指定实际值就可以了.

                  I'm starting new Angular application which I initialised with Angular-CLI (beta 22.1). But when I add test-data (5 values) to my chart it seems to scale wrong and only shows the first two values and streched them over the whole length of the graph (see picture).

                  The project is otherwise blank and does not contain any CSS whatsoever.

                  My app.component.html:

                  <div>
                      <canvas baseChart [datasets]="_numbers" [labels]="_labels" [options]="_chartOpt" [colors]="_chartColours" [legend]="_chartLegend" [chartType]="_chartType" width="600px">
                      </canvas>
                  <div>
                  

                  The app.component.ts

                  import { Component } from '@angular/core';
                  import { BaseChartDirective } from "ng2-charts/ng2-charts";
                  
                  @Component({
                    selector: 'app-root',
                    templateUrl: './app.component.html',
                    styleUrls: ['./app.component.css']
                  })
                  export class AppComponent {
                    private _numbers: any[] = [
                        {
                          label: "Test",
                          data: [10,2,6,7] // should cause 4 points in the chart
                       }
                    ];
                  
                    private _chartOpt: any = {
                          responsive: true
                    };
                  
                    public _chartColours:any[] = [];
                  
                    private _labels: string[] = [];
                    private _chartLegend: boolean = false;
                    private _chartType: string = "line";
                  }
                  

                  The chart.js library is added via the angular-cli.json:

                  "scripts": [
                           "../node_modules/chart.js/dist/Chart.bundle.min.js"
                        ],
                  

                  I really don't know where I'm going wrong. I've tried many different options (responsive: true/false, maintainAspectRatio : true/false, wrapping the <canvas> in <div> and without, CSS Styles, width/height attributes, ...) but can't seem to get this one to work. I even downgraded the ng2-charts version to one that I reviously worked with, but with no luck.

                  Let me know if you need anymore code.

                  解决方案

                  labels property must be defined along with values. According to documentation for properties:

                  labels (?Array) - x axis labels. It's necessary for charts: line, bar and radar.

                  So specifying actual values for labels will do the trick.

                  这篇关于Ng2-Charts Linechart 仅显示前 2 个两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                  Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                  How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                  Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                  Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                  How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)
                • <tfoot id='B0jIF'></tfoot>
                    <tbody id='B0jIF'></tbody>
                  <legend id='B0jIF'><style id='B0jIF'><dir id='B0jIF'><q id='B0jIF'></q></dir></style></legend>
                      <bdo id='B0jIF'></bdo><ul id='B0jIF'></ul>

                      • <i id='B0jIF'><tr id='B0jIF'><dt id='B0jIF'><q id='B0jIF'><span id='B0jIF'><b id='B0jIF'><form id='B0jIF'><ins id='B0jIF'></ins><ul id='B0jIF'></ul><sub id='B0jIF'></sub></form><legend id='B0jIF'></legend><bdo id='B0jIF'><pre id='B0jIF'><center id='B0jIF'></center></pre></bdo></b><th id='B0jIF'></th></span></q></dt></tr></i><div id='B0jIF'><tfoot id='B0jIF'></tfoot><dl id='B0jIF'><fieldset id='B0jIF'></fieldset></dl></div>

                        <small id='B0jIF'></small><noframes id='B0jIF'>