Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Basic pie chart #47

Closed
AlexanderBrese opened this issue Apr 18, 2018 · 2 comments
Closed

Basic pie chart #47

AlexanderBrese opened this issue Apr 18, 2018 · 2 comments

Comments

@AlexanderBrese
Copy link

AlexanderBrese commented Apr 18, 2018

Code

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

class BarCounter {
  final int domain;
  final int measure;
  final charts.Color color;

  BarCounter(this.domain, this.measure, Color color)
      : this.color = new charts.Color(
            r: color.red, g: color.green, b: color.blue, a: color.alpha);
}

class Statistics {
  Statistics(
      this.trackAmount,
      this.barAmount,
      this.lastTrackDate,
      this.barCounters,
      this.tracksMonthly,
      this.tracksDaily,
      this.speedCounters);

  int trackAmount;
  int barAmount;
  DateTime lastTrackDate;
  List<BarCounter> barCounters;
  List<int> tracksMonthly;
  List<int> tracksDaily;
  List<int> speedCounters;
}

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

  BarCounterChart(List<BarCounter> barCounters, {this.animate})
      : this.seriesList = [
          new charts.Series<BarCounter, int>(
            id: 'BarCounter',
            domainFn: (BarCounter barCounter, _) => barCounter.domain,
            measureFn: (BarCounter barCounter, _) => barCounter.measure,
            colorFn: (BarCounter barCounter, _) => barCounter.color,
            data: barCounters,
          ),
        ];

  @override
  Widget build(BuildContext context) {
    return new charts.PieChart<BarCounter, int>(seriesList, animate: animate);
  }
}

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.0
  intl: ^0.15.6
  charts_flutter: ^0.2.0
  timeago: ^1.2.1
  flutter_gallery_assets:
      git:
        url: https://flutter.googlesource.com/gallery-assets
        ref: d318485f208376e06d7e330d9f191141d14722b8

Error message

Another exception was thrown: type '(BarCounter, int) => int' is not a subtype of type '(dynamic, int) => dynamic'
@AlexanderBrese AlexanderBrese changed the title Error with basic pie chart Basic pie chart Apr 18, 2018
@rsnider19
Copy link

I am getting this same error after upgrading to Dart 2. I Think it has to do with Dart 2's strong mode for typing.

@lorrainekan
Copy link
Contributor

lorrainekan commented Apr 26, 2018

You just need

new charts.PieChart<BarCounter>(...

In an upcoming release, you should only need new charts.PieChart(... since we removed the generic from the chart itself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants