mirror of
https://github.com/flutter/samples.git
synced 2026-04-30 11:36:35 +00:00
web/chart: fix sample (#909)
This commit is contained in:
@@ -28,10 +28,11 @@ class DatumLegendOptions extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
DatumLegendOptions(this.seriesList, {this.animate});
|
||||
const DatumLegendOptions(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory DatumLegendOptions.withSampleData() {
|
||||
return new DatumLegendOptions(
|
||||
return DatumLegendOptions(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -43,22 +44,22 @@ class DatumLegendOptions extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory DatumLegendOptions.withRandomData() {
|
||||
return new DatumLegendOptions(_createRandomData());
|
||||
return DatumLegendOptions(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, int>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new LinearSales(0, random.nextInt(100)),
|
||||
new LinearSales(1, random.nextInt(100)),
|
||||
new LinearSales(2, random.nextInt(100)),
|
||||
new LinearSales(3, random.nextInt(100)),
|
||||
LinearSales(0, random.nextInt(100)),
|
||||
LinearSales(1, random.nextInt(100)),
|
||||
LinearSales(2, random.nextInt(100)),
|
||||
LinearSales(3, random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -70,14 +71,14 @@ class DatumLegendOptions extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.PieChart(
|
||||
return charts.PieChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
// Add the legend behavior to the chart to turn on legends.
|
||||
// This example shows how to change the position and justification of
|
||||
// the legend, in addition to altering the max rows and padding.
|
||||
behaviors: [
|
||||
new charts.DatumLegend(
|
||||
charts.DatumLegend(
|
||||
// Positions for "start" and "end" will be left and right respectively
|
||||
// for widgets with a build context that has directionality ltr.
|
||||
// For rtl, "start" and "end" will be right and left respectively.
|
||||
@@ -96,7 +97,7 @@ class DatumLegendOptions extends StatelessWidget {
|
||||
// rows before adding a new column.
|
||||
desiredMaxRows: 2,
|
||||
// This defines the padding around each legend entry.
|
||||
cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
cellPadding: const EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
// Render the legend entry text with custom styles.
|
||||
entryTextStyle: charts.TextStyleSpec(
|
||||
color: charts.MaterialPalette.purple.shadeDefault,
|
||||
@@ -110,14 +111,14 @@ class DatumLegendOptions extends StatelessWidget {
|
||||
/// Create series list with one series
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 100),
|
||||
new LinearSales(1, 75),
|
||||
new LinearSales(2, 25),
|
||||
new LinearSales(3, 5),
|
||||
LinearSales(0, 100),
|
||||
LinearSales(1, 75),
|
||||
LinearSales(2, 25),
|
||||
LinearSales(3, 5),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
@@ -28,13 +28,14 @@ import 'package:charts_flutter/flutter.dart' as charts;
|
||||
///
|
||||
/// Also shows the option to provide a custom measure formatter.
|
||||
class DatumLegendWithMeasures extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final List<charts.Series<LinearSales, int>> seriesList;
|
||||
final bool animate;
|
||||
|
||||
DatumLegendWithMeasures(this.seriesList, {this.animate});
|
||||
const DatumLegendWithMeasures(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory DatumLegendWithMeasures.withSampleData() {
|
||||
return new DatumLegendWithMeasures(
|
||||
return DatumLegendWithMeasures(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -46,22 +47,22 @@ class DatumLegendWithMeasures extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory DatumLegendWithMeasures.withRandomData() {
|
||||
return new DatumLegendWithMeasures(_createRandomData());
|
||||
return DatumLegendWithMeasures(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, int>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new LinearSales(2014, random.nextInt(100)),
|
||||
new LinearSales(2015, random.nextInt(100)),
|
||||
new LinearSales(2016, random.nextInt(100)),
|
||||
new LinearSales(2017, random.nextInt(100)),
|
||||
LinearSales(2014, random.nextInt(100)),
|
||||
LinearSales(2015, random.nextInt(100)),
|
||||
LinearSales(2016, random.nextInt(100)),
|
||||
LinearSales(2017, random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -73,7 +74,7 @@ class DatumLegendWithMeasures extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.PieChart(
|
||||
return charts.PieChart<int>(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
// Add the legend behavior to the chart to turn on legends.
|
||||
@@ -84,13 +85,13 @@ class DatumLegendWithMeasures extends StatelessWidget {
|
||||
// This section is excluded from being copied to the gallery.
|
||||
// This is added in order to generate the image for the gallery to show
|
||||
// an initial selection so that measure values are shown in the gallery.
|
||||
new charts.InitialSelection(
|
||||
charts.InitialSelection(
|
||||
selectedDataConfig: [
|
||||
new charts.SeriesDatumConfig('Sales', 0),
|
||||
charts.SeriesDatumConfig('Sales', 0),
|
||||
],
|
||||
),
|
||||
// EXCLUDE_FROM_GALLERY_DOCS_END
|
||||
new charts.DatumLegend(
|
||||
charts.DatumLegend(
|
||||
// Positions for "start" and "end" will be left and right respectively
|
||||
// for widgets with a build context that has directionality ltr.
|
||||
// For rtl, "start" and "end" will be right and left respectively.
|
||||
@@ -102,7 +103,7 @@ class DatumLegendWithMeasures extends StatelessWidget {
|
||||
// legend entries will grow as new rows first instead of a new column.
|
||||
horizontalFirst: false,
|
||||
// This defines the padding around each legend entry.
|
||||
cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
cellPadding: const EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
// Set [showMeasures] to true to display measures in series legend.
|
||||
showMeasures: true,
|
||||
// Configure the measure value to be shown by default in the legend.
|
||||
@@ -120,14 +121,14 @@ class DatumLegendWithMeasures extends StatelessWidget {
|
||||
/// Create series list with one series
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(2014, 100),
|
||||
new LinearSales(2015, 75),
|
||||
new LinearSales(2016, 25),
|
||||
new LinearSales(2017, 5),
|
||||
LinearSales(2014, 100),
|
||||
LinearSales(2015, 75),
|
||||
LinearSales(2016, 25),
|
||||
LinearSales(2017, 5),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
@@ -24,10 +24,11 @@ class DefaultHiddenSeriesLegend extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
DefaultHiddenSeriesLegend(this.seriesList, {this.animate});
|
||||
const DefaultHiddenSeriesLegend(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory DefaultHiddenSeriesLegend.withSampleData() {
|
||||
return new DefaultHiddenSeriesLegend(
|
||||
return DefaultHiddenSeriesLegend(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -39,61 +40,61 @@ class DefaultHiddenSeriesLegend extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory DefaultHiddenSeriesLegend.withRandomData() {
|
||||
return new DefaultHiddenSeriesLegend(_createRandomData());
|
||||
return DefaultHiddenSeriesLegend(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -105,16 +106,16 @@ class DefaultHiddenSeriesLegend extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.grouped,
|
||||
// Add the series legend behavior to the chart to turn on series legends.
|
||||
// By default the legend will display above the chart.
|
||||
behaviors: [
|
||||
new charts.SeriesLegend(
|
||||
charts.SeriesLegend(
|
||||
// Configures the "Other" series to be hidden on first chart draw.
|
||||
defaultHiddenSeries: ['Other'],
|
||||
defaultHiddenSeries: const ['Other'],
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -123,53 +124,53 @@ class DefaultHiddenSeriesLegend extends StatelessWidget {
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', 25),
|
||||
new OrdinalSales('2015', 50),
|
||||
new OrdinalSales('2016', 10),
|
||||
new OrdinalSales('2017', 20),
|
||||
OrdinalSales('2014', 25),
|
||||
OrdinalSales('2015', 50),
|
||||
OrdinalSales('2016', 10),
|
||||
OrdinalSales('2017', 20),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', 10),
|
||||
new OrdinalSales('2015', 15),
|
||||
new OrdinalSales('2016', 50),
|
||||
new OrdinalSales('2017', 45),
|
||||
OrdinalSales('2014', 10),
|
||||
OrdinalSales('2015', 15),
|
||||
OrdinalSales('2016', 50),
|
||||
OrdinalSales('2017', 45),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', 20),
|
||||
new OrdinalSales('2015', 35),
|
||||
new OrdinalSales('2016', 15),
|
||||
new OrdinalSales('2017', 10),
|
||||
OrdinalSales('2014', 20),
|
||||
OrdinalSales('2015', 35),
|
||||
OrdinalSales('2016', 15),
|
||||
OrdinalSales('2017', 10),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -29,15 +29,16 @@ class IconRenderer extends charts.CustomSymbolRenderer {
|
||||
IconRenderer(this.iconData);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, {Size size, Color color, bool enabled}) {
|
||||
Widget build(BuildContext context,
|
||||
{Size size, Color color, bool enabled = true}) {
|
||||
// Lighten the color if the symbol is not enabled
|
||||
// Example: If user has tapped on a Series deselecting it.
|
||||
if (!enabled) {
|
||||
color = color.withOpacity(0.26);
|
||||
}
|
||||
|
||||
return new SizedBox.fromSize(
|
||||
size: size, child: new Icon(iconData, color: color, size: 12.0));
|
||||
return SizedBox.fromSize(
|
||||
size: size, child: Icon(iconData, color: color, size: 12.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +46,11 @@ class LegendWithCustomSymbol extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
LegendWithCustomSymbol(this.seriesList, {this.animate});
|
||||
const LegendWithCustomSymbol(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory LegendWithCustomSymbol.withSampleData() {
|
||||
return new LegendWithCustomSymbol(
|
||||
return LegendWithCustomSymbol(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -60,61 +62,61 @@ class LegendWithCustomSymbol extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory LegendWithCustomSymbol.withRandomData() {
|
||||
return new LegendWithCustomSymbol(_createRandomData());
|
||||
return LegendWithCustomSymbol(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -126,7 +128,7 @@ class LegendWithCustomSymbol extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.grouped,
|
||||
@@ -135,62 +137,62 @@ class LegendWithCustomSymbol extends StatelessWidget {
|
||||
//
|
||||
// To change the symbol used in the legend, set the renderer attribute of
|
||||
// symbolRendererKey to a SymbolRenderer.
|
||||
behaviors: [new charts.SeriesLegend()],
|
||||
defaultRenderer: new charts.BarRendererConfig(
|
||||
symbolRenderer: new IconRenderer(Icons.cloud)),
|
||||
behaviors: [charts.SeriesLegend()],
|
||||
defaultRenderer:
|
||||
charts.BarRendererConfig(symbolRenderer: IconRenderer(Icons.cloud)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', 25),
|
||||
new OrdinalSales('2015', 50),
|
||||
new OrdinalSales('2016', 10),
|
||||
new OrdinalSales('2017', 20),
|
||||
OrdinalSales('2014', 25),
|
||||
OrdinalSales('2015', 50),
|
||||
OrdinalSales('2016', 10),
|
||||
OrdinalSales('2017', 20),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', 10),
|
||||
new OrdinalSales('2015', 15),
|
||||
new OrdinalSales('2016', 50),
|
||||
new OrdinalSales('2017', 45),
|
||||
OrdinalSales('2014', 10),
|
||||
OrdinalSales('2015', 15),
|
||||
OrdinalSales('2016', 50),
|
||||
OrdinalSales('2017', 45),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', 20),
|
||||
new OrdinalSales('2015', 35),
|
||||
new OrdinalSales('2016', 15),
|
||||
new OrdinalSales('2017', 10),
|
||||
OrdinalSales('2014', 20),
|
||||
OrdinalSales('2015', 35),
|
||||
OrdinalSales('2016', 15),
|
||||
OrdinalSales('2017', 10),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -26,55 +26,55 @@ import 'simple_series_legend.dart';
|
||||
|
||||
List<GalleryScaffold> buildGallery() {
|
||||
return [
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Series Legend',
|
||||
subtitle: 'A series legend for a bar chart with default settings',
|
||||
childBuilder: () => new SimpleSeriesLegend.withRandomData(),
|
||||
childBuilder: () => SimpleSeriesLegend.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Series Legend Options',
|
||||
subtitle:
|
||||
'A series legend with custom positioning and spacing for a bar chart',
|
||||
childBuilder: () => new LegendOptions.withRandomData(),
|
||||
childBuilder: () => LegendOptions.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Series Legend Custom Symbol',
|
||||
subtitle: 'A series legend using a custom symbol renderer',
|
||||
childBuilder: () => new LegendWithCustomSymbol.withRandomData(),
|
||||
childBuilder: () => LegendWithCustomSymbol.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Default Hidden Series Legend',
|
||||
subtitle: 'A series legend showing a series hidden by default',
|
||||
childBuilder: () => new DefaultHiddenSeriesLegend.withRandomData(),
|
||||
childBuilder: () => DefaultHiddenSeriesLegend.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Series legend with measures',
|
||||
subtitle: 'Series legend with measures and measure formatting',
|
||||
childBuilder: () => new LegendWithMeasures.withRandomData(),
|
||||
childBuilder: () => LegendWithMeasures.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.pie_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.pie_chart),
|
||||
title: 'Datum Legend',
|
||||
subtitle: 'A datum legend for a pie chart with default settings',
|
||||
childBuilder: () => new SimpleDatumLegend.withRandomData(),
|
||||
childBuilder: () => SimpleDatumLegend.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.pie_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.pie_chart),
|
||||
title: 'Datum Legend Options',
|
||||
subtitle:
|
||||
'A datum legend with custom positioning and spacing for a pie chart',
|
||||
childBuilder: () => new DatumLegendOptions.withRandomData(),
|
||||
childBuilder: () => DatumLegendOptions.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.pie_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.pie_chart),
|
||||
title: 'Datum legend with measures',
|
||||
subtitle: 'Datum legend with measures and measure formatting',
|
||||
childBuilder: () => new DatumLegendWithMeasures.withRandomData(),
|
||||
childBuilder: () => DatumLegendWithMeasures.withRandomData(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ class LegendOptions extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
LegendOptions(this.seriesList, {this.animate});
|
||||
const LegendOptions(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory LegendOptions.withSampleData() {
|
||||
return new LegendOptions(
|
||||
return LegendOptions(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -43,61 +44,61 @@ class LegendOptions extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory LegendOptions.withRandomData() {
|
||||
return new LegendOptions(_createRandomData());
|
||||
return LegendOptions(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -109,7 +110,7 @@ class LegendOptions extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.grouped,
|
||||
@@ -117,7 +118,7 @@ class LegendOptions extends StatelessWidget {
|
||||
// This example shows how to change the position and justification of
|
||||
// the legend, in addition to altering the max rows and padding.
|
||||
behaviors: [
|
||||
new charts.SeriesLegend(
|
||||
charts.SeriesLegend(
|
||||
// Positions for "start" and "end" will be left and right respectively
|
||||
// for widgets with a build context that has directionality ltr.
|
||||
// For rtl, "start" and "end" will be right and left respectively.
|
||||
@@ -136,7 +137,7 @@ class LegendOptions extends StatelessWidget {
|
||||
// rows before adding a new column.
|
||||
desiredMaxRows: 2,
|
||||
// This defines the padding around each legend entry.
|
||||
cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
cellPadding: const EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
// Render the legend entry text with custom styles.
|
||||
entryTextStyle: charts.TextStyleSpec(
|
||||
color: charts.MaterialPalette.purple.shadeDefault,
|
||||
@@ -150,53 +151,53 @@ class LegendOptions extends StatelessWidget {
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', 25),
|
||||
new OrdinalSales('2015', 50),
|
||||
new OrdinalSales('2016', 10),
|
||||
new OrdinalSales('2017', 20),
|
||||
OrdinalSales('2014', 25),
|
||||
OrdinalSales('2015', 50),
|
||||
OrdinalSales('2016', 10),
|
||||
OrdinalSales('2017', 20),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', 10),
|
||||
new OrdinalSales('2015', 15),
|
||||
new OrdinalSales('2016', 50),
|
||||
new OrdinalSales('2017', 45),
|
||||
OrdinalSales('2014', 10),
|
||||
OrdinalSales('2015', 15),
|
||||
OrdinalSales('2016', 50),
|
||||
OrdinalSales('2017', 45),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', 20),
|
||||
new OrdinalSales('2015', 35),
|
||||
new OrdinalSales('2016', 15),
|
||||
new OrdinalSales('2017', 10),
|
||||
OrdinalSales('2014', 20),
|
||||
OrdinalSales('2015', 35),
|
||||
OrdinalSales('2016', 15),
|
||||
OrdinalSales('2017', 10),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -32,10 +32,11 @@ class LegendWithMeasures extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
LegendWithMeasures(this.seriesList, {this.animate});
|
||||
const LegendWithMeasures(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory LegendWithMeasures.withSampleData() {
|
||||
return new LegendWithMeasures(
|
||||
return LegendWithMeasures(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -47,61 +48,61 @@ class LegendWithMeasures extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory LegendWithMeasures.withRandomData() {
|
||||
return new LegendWithMeasures(_createRandomData());
|
||||
return LegendWithMeasures(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -113,7 +114,7 @@ class LegendWithMeasures extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.grouped,
|
||||
@@ -125,16 +126,16 @@ class LegendWithMeasures extends StatelessWidget {
|
||||
// This section is excluded from being copied to the gallery.
|
||||
// This is added in order to generate the image for the gallery to show
|
||||
// an initial selection so that measure values are shown in the gallery.
|
||||
new charts.InitialSelection(
|
||||
charts.InitialSelection(
|
||||
selectedDataConfig: [
|
||||
new charts.SeriesDatumConfig('Desktop', '2016'),
|
||||
new charts.SeriesDatumConfig('Tablet', '2016'),
|
||||
new charts.SeriesDatumConfig('Mobile', '2016'),
|
||||
new charts.SeriesDatumConfig('Other', '2016'),
|
||||
charts.SeriesDatumConfig('Desktop', '2016'),
|
||||
charts.SeriesDatumConfig('Tablet', '2016'),
|
||||
charts.SeriesDatumConfig('Mobile', '2016'),
|
||||
charts.SeriesDatumConfig('Other', '2016'),
|
||||
],
|
||||
),
|
||||
// EXCLUDE_FROM_GALLERY_DOCS_END
|
||||
new charts.SeriesLegend(
|
||||
charts.SeriesLegend(
|
||||
// Positions for "start" and "end" will be left and right respectively
|
||||
// for widgets with a build context that has directionality ltr.
|
||||
// For rtl, "start" and "end" will be right and left respectively.
|
||||
@@ -146,7 +147,7 @@ class LegendWithMeasures extends StatelessWidget {
|
||||
// legend entries will grow as new rows first instead of a new column.
|
||||
horizontalFirst: false,
|
||||
// This defines the padding around each legend entry.
|
||||
cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
cellPadding: const EdgeInsets.only(right: 4.0, bottom: 4.0),
|
||||
// Set show measures to true to display measures in series legend,
|
||||
// when the datum is selected.
|
||||
showMeasures: true,
|
||||
@@ -163,53 +164,53 @@ class LegendWithMeasures extends StatelessWidget {
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', 25),
|
||||
new OrdinalSales('2015', 50),
|
||||
OrdinalSales('2014', 25),
|
||||
OrdinalSales('2015', 50),
|
||||
// Purposely have a missing datum for 2016 to show the null measure format
|
||||
new OrdinalSales('2017', 20),
|
||||
OrdinalSales('2017', 20),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', 10),
|
||||
new OrdinalSales('2015', 15),
|
||||
new OrdinalSales('2016', 50),
|
||||
new OrdinalSales('2017', 45),
|
||||
OrdinalSales('2014', 10),
|
||||
OrdinalSales('2015', 15),
|
||||
OrdinalSales('2016', 50),
|
||||
OrdinalSales('2017', 45),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', 20),
|
||||
new OrdinalSales('2015', 35),
|
||||
new OrdinalSales('2016', 15),
|
||||
new OrdinalSales('2017', 10),
|
||||
OrdinalSales('2014', 20),
|
||||
OrdinalSales('2015', 35),
|
||||
OrdinalSales('2016', 15),
|
||||
OrdinalSales('2017', 10),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -24,10 +24,11 @@ class SimpleDatumLegend extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SimpleDatumLegend(this.seriesList, {this.animate});
|
||||
const SimpleDatumLegend(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory SimpleDatumLegend.withSampleData() {
|
||||
return new SimpleDatumLegend(
|
||||
return SimpleDatumLegend(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -39,22 +40,22 @@ class SimpleDatumLegend extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SimpleDatumLegend.withRandomData() {
|
||||
return new SimpleDatumLegend(_createRandomData());
|
||||
return SimpleDatumLegend(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, int>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new LinearSales(0, random.nextInt(100)),
|
||||
new LinearSales(1, random.nextInt(100)),
|
||||
new LinearSales(2, random.nextInt(100)),
|
||||
new LinearSales(3, random.nextInt(100)),
|
||||
LinearSales(0, random.nextInt(100)),
|
||||
LinearSales(1, random.nextInt(100)),
|
||||
LinearSales(2, random.nextInt(100)),
|
||||
LinearSales(3, random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -66,26 +67,26 @@ class SimpleDatumLegend extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.PieChart(
|
||||
return charts.PieChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
// Add the series legend behavior to the chart to turn on series legends.
|
||||
// By default the legend will display above the chart.
|
||||
behaviors: [new charts.DatumLegend()],
|
||||
behaviors: [charts.DatumLegend()],
|
||||
);
|
||||
}
|
||||
|
||||
/// Create series list with one series
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 100),
|
||||
new LinearSales(1, 75),
|
||||
new LinearSales(2, 25),
|
||||
new LinearSales(3, 5),
|
||||
LinearSales(0, 100),
|
||||
LinearSales(1, 75),
|
||||
LinearSales(2, 25),
|
||||
LinearSales(3, 5),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
@@ -24,10 +24,11 @@ class SimpleSeriesLegend extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SimpleSeriesLegend(this.seriesList, {this.animate});
|
||||
const SimpleSeriesLegend(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory SimpleSeriesLegend.withSampleData() {
|
||||
return new SimpleSeriesLegend(
|
||||
return SimpleSeriesLegend(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -39,61 +40,61 @@ class SimpleSeriesLegend extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SimpleSeriesLegend.withRandomData() {
|
||||
return new SimpleSeriesLegend(_createRandomData());
|
||||
return SimpleSeriesLegend(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -105,66 +106,66 @@ class SimpleSeriesLegend extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.grouped,
|
||||
// Add the series legend behavior to the chart to turn on series legends.
|
||||
// By default the legend will display above the chart.
|
||||
behaviors: [new charts.SeriesLegend()],
|
||||
behaviors: [charts.SeriesLegend()],
|
||||
);
|
||||
}
|
||||
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
final tabletSalesData = [
|
||||
new OrdinalSales('2014', 25),
|
||||
new OrdinalSales('2015', 50),
|
||||
new OrdinalSales('2016', 10),
|
||||
new OrdinalSales('2017', 20),
|
||||
OrdinalSales('2014', 25),
|
||||
OrdinalSales('2015', 50),
|
||||
OrdinalSales('2016', 10),
|
||||
OrdinalSales('2017', 20),
|
||||
];
|
||||
|
||||
final mobileSalesData = [
|
||||
new OrdinalSales('2014', 10),
|
||||
new OrdinalSales('2015', 15),
|
||||
new OrdinalSales('2016', 50),
|
||||
new OrdinalSales('2017', 45),
|
||||
OrdinalSales('2014', 10),
|
||||
OrdinalSales('2015', 15),
|
||||
OrdinalSales('2016', 50),
|
||||
OrdinalSales('2017', 45),
|
||||
];
|
||||
|
||||
final otherSalesData = [
|
||||
new OrdinalSales('2014', 20),
|
||||
new OrdinalSales('2015', 35),
|
||||
new OrdinalSales('2016', 15),
|
||||
new OrdinalSales('2017', 10),
|
||||
OrdinalSales('2014', 20),
|
||||
OrdinalSales('2015', 35),
|
||||
OrdinalSales('2016', 15),
|
||||
OrdinalSales('2017', 10),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tabletSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Other',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
Reference in New Issue
Block a user