如何在容器中显示图表?

时间:2019-02-05 19:14:50

标签: charts flutter

我是扑扑扑扑的新手。所以,请忍受我。

我尝试在Container小部件中显示一个由Charts_flutter库制成的图表(请参见代码行10)。我试图在那里调用CustomRoundedBar对象,但这给了我一个类型错误,告诉我不能在预期为“ Widget”类型的地方加载“ Type”类型。

我该怎么做才能在容器中显示图表?或任何其他小部件?

我们非常感谢您的帮助。

import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;

class Insights extends StatelessWidget {


  @override
  Widget build(BuildContext context) {
    return Container(
      //child: Text('This is text in a Container'),
    );
  }
}




class CustomRoundedBars extends StatelessWidget {
  final List<charts.Series> seriesList;
  final bool animate;

  CustomRoundedBars(this.seriesList, {this.animate});

  /// Creates a [BarChart] with custom rounded bars.
  factory CustomRoundedBars.withSampleData() {
    return new CustomRoundedBars(
      _createSampleData(),
      // Disable animations for image tests.
      animate: false,
    );
  }


  @override
  Widget build(BuildContext context) {
    return new charts.BarChart(
      seriesList,
      animate: animate,
      defaultRenderer: new charts.BarRendererConfig(
        // By default, bar renderer will draw rounded bars with a constant
        // radius of 100.
        // To not have any rounded corners, use [NoCornerStrategy]
        // To change the radius of the bars, use [ConstCornerStrategy]
          cornerStrategy: const charts.ConstCornerStrategy(30)),
    );
  }

  /// Create one series with sample hard coded data.
  static List<charts.Series<OrdinalSales, String>> _createSampleData() {
    final data = [
      new OrdinalSales('2014', 5),
      new OrdinalSales('2015', 25),
      new OrdinalSales('2016', 100),
      new OrdinalSales('2017', 75),
    ];

    return [
      new charts.Series<OrdinalSales, String>(
        id: 'Sales',
        colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
        domainFn: (OrdinalSales sales, _) => sales.year,
        measureFn: (OrdinalSales sales, _) => sales.sales,
        data: data,
      )
    ];
  }
}

/// Sample ordinal data type.
class OrdinalSales {
  final String year;
  final int sales;

  OrdinalSales(this.year, this.sales);
}

1 个答案:

答案 0 :(得分:0)

构造图表并将其作为 -p <percent_free> Allocate memory till the available memory in the system is <percent_free> of total memory. If the percentage of available memory to total memory on the system drops, the tool will free memory till either the desired percentage is achieved or it runs out of memory to free. -S Simulate memory pressure on the system by placing it artificially for <sleep_seconds> duration at the "warn" or "critical" level. -s <sleep_seconds> Duration to wait before allocating or freeing memory if applying real pressure. In case of simulating memory pressure, this is the duration the system will be maintained at an artifical memory level. 参数传递给child的构造函数。

Container