dibaloke
4/2/2019 - 10:44 AM

Flutter Circular Chart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  
  

  @override
  Widget build(BuildContext context) {

    var data=[
      Sales("Sun",50,Colors.red),
      Sales("Mon",70,Colors.green),
      Sales("Tue",100,Colors.yellow),
      Sales("Wed",50,Colors.pink),
      Sales("Thu",145,Colors.purple),
      Sales("Fri",190,Colors.brown),
      Sales("Sat",30,Colors.orange),
      


    ];

    var series=[
      charts.Series(
        domainFn: (Sales sales,_)=>sales.day,
        measureFn: (Sales sales,_)=>sales.sold,
        colorFn: (Sales sales,_)=>sales.color,
        id:'Sales',
        data: data

      )
         

    ];
    var chart=charts.PieChart(
      series,
      defaultRenderer: charts.ArcRendererConfig(
        arcRendererDecorators: [charts.ArcLabelDecorator()]
      ),
      animate: true,
    

    );
    return Scaffold(
      
      appBar: AppBar(title: Text("Flutter Simple Bar Chart"),),
      body: Padding(
        padding: const EdgeInsets.all(12.0),
        
        child: Column(
          children: <Widget>[Text("Sales Analysis",style: TextStyle(fontSize: 30),),
            SizedBox(height:600,child: chart),
          ],
        ),
      ),
    );
  }
}

class Sales {
  final String day;
  final int sold;
  final charts.Color color; 
  Sales(this.day, this.sold,Color color)
  :this.color=charts.Color(r:color.red,g: color.green,b: color.blue,a: color.alpha);
}
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  
  

  @override
  Widget build(BuildContext context) {

    var data=[
      Sales("Sun",50,Colors.red),
      Sales("Mon",70,Colors.green),
      Sales("Tue",100,Colors.yellow),
      Sales("Wed",50,Colors.pink),
      Sales("Thu",145,Colors.purple),
      Sales("Fri",190,Colors.brown),
      Sales("Sat",30,Colors.orange),
      


    ];

    var series=[
      charts.Series(
        domainFn: (Sales sales,_)=>sales.day,
        measureFn: (Sales sales,_)=>sales.sold,
        colorFn: (Sales sales,_)=>sales.color,
        id:'Sales',
        data: data

      )
         

    ];
    var chart=charts.PieChart(
      series,
      defaultRenderer: charts.ArcRendererConfig(
        arcRendererDecorators: [charts.ArcLabelDecorator()],
        arcWidth: 100
      ),
      animate: true,
    
    

    );
    return Scaffold(
      
      appBar: AppBar(title: Text("Flutter Simple Bar Chart"),),
      body: Padding(
        padding: const EdgeInsets.all(12.0),
        
        child: Column(
          children: <Widget>[Text("Sales Analysis",style: TextStyle(fontSize: 30),),
            SizedBox(height:600,child: chart),
          ],
        ),
      ),
    );
  }
}

class Sales {
  final String day;
  final int sold;
  final charts.Color color; 
  Sales(this.day, this.sold,Color color)
  :this.color=charts.Color(r:color.red,g: color.green,b: color.blue,a: color.alpha);
}