mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 22:38:42 +00:00
web/chart: fix sample (#909)
This commit is contained in:
@@ -32,95 +32,93 @@ import 'sliding_viewport_on_selection.dart';
|
||||
|
||||
List<GalleryScaffold> buildGallery() {
|
||||
return [
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Selection Bar Highlight',
|
||||
subtitle: 'Simple bar chart with tap activation',
|
||||
childBuilder: () => new SelectionBarHighlight.withRandomData(),
|
||||
childBuilder: () => SelectionBarHighlight.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Selection Line Highlight',
|
||||
subtitle: 'Line chart with tap and drag activation',
|
||||
childBuilder: () => new SelectionLineHighlight.withRandomData(),
|
||||
childBuilder: () => SelectionLineHighlight.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Selection Line Highlight Custom Shape',
|
||||
subtitle: 'Line chart with tap and drag activation and a custom shape',
|
||||
childBuilder: () =>
|
||||
new SelectionLineHighlightCustomShape.withRandomData(),
|
||||
childBuilder: () => SelectionLineHighlightCustomShape.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Selection Scatter Plot Highlight',
|
||||
subtitle: 'Scatter plot chart with tap and drag activation',
|
||||
childBuilder: () => new SelectionScatterPlotHighlight.withRandomData(),
|
||||
childBuilder: () => SelectionScatterPlotHighlight.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Selection Callback Example',
|
||||
subtitle: 'Timeseries that updates external components on selection',
|
||||
childBuilder: () => new SelectionCallbackExample.withRandomData(),
|
||||
childBuilder: () => SelectionCallbackExample.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'User managed selection',
|
||||
subtitle:
|
||||
'Example where selection can be set and cleared programmatically',
|
||||
childBuilder: () => new SelectionUserManaged.withRandomData(),
|
||||
childBuilder: () => SelectionUserManaged.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Bar Chart with initial selection',
|
||||
subtitle: 'Single series with initial selection',
|
||||
childBuilder: () => new InitialSelection.withRandomData(),
|
||||
childBuilder: () => InitialSelection.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Line Chart with Chart Titles',
|
||||
subtitle: 'Line chart with four chart titles',
|
||||
childBuilder: () => new ChartTitleLine.withRandomData(),
|
||||
childBuilder: () => ChartTitleLine.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.flag),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.flag),
|
||||
title: 'Line Chart with Slider',
|
||||
subtitle: 'Line chart with a slider behavior',
|
||||
childBuilder: () => new SliderLine.withRandomData(),
|
||||
childBuilder: () => SliderLine.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Percent of Domain',
|
||||
subtitle: 'Stacked bar chart with measures calculated as percent of ' +
|
||||
'domain',
|
||||
childBuilder: () => new PercentOfDomainBarChart.withRandomData(),
|
||||
subtitle:
|
||||
'Stacked bar chart with measures calculated as percent of ' 'domain',
|
||||
childBuilder: () => PercentOfDomainBarChart.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Percent of Domain by Category',
|
||||
subtitle: 'Grouped stacked bar chart with measures calculated as '
|
||||
'percent of domain and series category',
|
||||
childBuilder: () =>
|
||||
new PercentOfDomainByCategoryBarChart.withRandomData(),
|
||||
childBuilder: () => PercentOfDomainByCategoryBarChart.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Percent of Series',
|
||||
subtitle: 'Grouped bar chart with measures calculated as percent of ' +
|
||||
'series',
|
||||
childBuilder: () => new PercentOfSeriesBarChart.withRandomData(),
|
||||
subtitle:
|
||||
'Grouped bar chart with measures calculated as percent of ' 'series',
|
||||
childBuilder: () => PercentOfSeriesBarChart.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Sliding viewport on domain selection',
|
||||
subtitle: 'Center viewport on selected domain',
|
||||
childBuilder: () => new SlidingViewportOnSelection.withRandomData(),
|
||||
childBuilder: () => SlidingViewportOnSelection.withRandomData(),
|
||||
),
|
||||
new GalleryScaffold(
|
||||
listTileIcon: new Icon(Icons.insert_chart),
|
||||
GalleryScaffold(
|
||||
listTileIcon: const Icon(Icons.insert_chart),
|
||||
title: 'Initial hint animation ',
|
||||
subtitle: 'Animate into final viewport',
|
||||
childBuilder: () => new InitialHintAnimation.withRandomData(),
|
||||
childBuilder: () => InitialHintAnimation.withRandomData(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -26,11 +26,12 @@ class ChartTitleLine extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
ChartTitleLine(this.seriesList, {this.animate});
|
||||
const ChartTitleLine(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [LineChart] with sample data and no transition.
|
||||
factory ChartTitleLine.withSampleData() {
|
||||
return new ChartTitleLine(
|
||||
return ChartTitleLine(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -42,22 +43,22 @@ class ChartTitleLine extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory ChartTitleLine.withRandomData() {
|
||||
return new ChartTitleLine(_createRandomData());
|
||||
return ChartTitleLine(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, num>> _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,
|
||||
@@ -69,7 +70,7 @@ class ChartTitleLine extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.LineChart(
|
||||
return charts.LineChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
// Configures four [ChartTitle] behaviors to render titles in each chart
|
||||
@@ -77,7 +78,7 @@ class ChartTitleLine extends StatelessWidget {
|
||||
// of the chart. The other titles are aligned with the middle of the draw
|
||||
// area.
|
||||
behaviors: [
|
||||
new charts.ChartTitle('Top title text',
|
||||
charts.ChartTitle('Top title text',
|
||||
subTitle: 'Top sub-title text',
|
||||
behaviorPosition: charts.BehaviorPosition.top,
|
||||
titleOutsideJustification: charts.OutsideJustification.start,
|
||||
@@ -86,15 +87,15 @@ class ChartTitleLine extends StatelessWidget {
|
||||
// The top tick label may extend upwards into the top margin region
|
||||
// if it is located at the top of the draw area.
|
||||
innerPadding: 18),
|
||||
new charts.ChartTitle('Bottom title text',
|
||||
charts.ChartTitle('Bottom title text',
|
||||
behaviorPosition: charts.BehaviorPosition.bottom,
|
||||
titleOutsideJustification:
|
||||
charts.OutsideJustification.middleDrawArea),
|
||||
new charts.ChartTitle('Start title',
|
||||
charts.ChartTitle('Start title',
|
||||
behaviorPosition: charts.BehaviorPosition.start,
|
||||
titleOutsideJustification:
|
||||
charts.OutsideJustification.middleDrawArea),
|
||||
new charts.ChartTitle('End title',
|
||||
charts.ChartTitle('End title',
|
||||
behaviorPosition: charts.BehaviorPosition.end,
|
||||
titleOutsideJustification:
|
||||
charts.OutsideJustification.middleDrawArea),
|
||||
@@ -105,14 +106,14 @@ class ChartTitleLine extends StatelessWidget {
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 5),
|
||||
new LinearSales(1, 25),
|
||||
new LinearSales(2, 100),
|
||||
new LinearSales(3, 75),
|
||||
LinearSales(0, 5),
|
||||
LinearSales(1, 25),
|
||||
LinearSales(2, 100),
|
||||
LinearSales(3, 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
@@ -51,11 +51,12 @@ class InitialHintAnimation extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
InitialHintAnimation(this.seriesList, {this.animate});
|
||||
const InitialHintAnimation(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [BarChart] with sample data and no transition.
|
||||
factory InitialHintAnimation.withSampleData() {
|
||||
return new InitialHintAnimation(
|
||||
return InitialHintAnimation(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -67,35 +68,35 @@ class InitialHintAnimation extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory InitialHintAnimation.withRandomData() {
|
||||
return new InitialHintAnimation(_createRandomData());
|
||||
return InitialHintAnimation(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
new OrdinalSales('2018', random.nextInt(100)),
|
||||
new OrdinalSales('2019', random.nextInt(100)),
|
||||
new OrdinalSales('2020', random.nextInt(100)),
|
||||
new OrdinalSales('2021', random.nextInt(100)),
|
||||
new OrdinalSales('2022', random.nextInt(100)),
|
||||
new OrdinalSales('2023', random.nextInt(100)),
|
||||
new OrdinalSales('2024', random.nextInt(100)),
|
||||
new OrdinalSales('2025', random.nextInt(100)),
|
||||
new OrdinalSales('2026', random.nextInt(100)),
|
||||
new OrdinalSales('2027', random.nextInt(100)),
|
||||
new OrdinalSales('2028', random.nextInt(100)),
|
||||
new OrdinalSales('2029', random.nextInt(100)),
|
||||
new OrdinalSales('2030', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2018', random.nextInt(100)),
|
||||
OrdinalSales('2019', random.nextInt(100)),
|
||||
OrdinalSales('2020', random.nextInt(100)),
|
||||
OrdinalSales('2021', random.nextInt(100)),
|
||||
OrdinalSales('2022', random.nextInt(100)),
|
||||
OrdinalSales('2023', random.nextInt(100)),
|
||||
OrdinalSales('2024', random.nextInt(100)),
|
||||
OrdinalSales('2025', random.nextInt(100)),
|
||||
OrdinalSales('2026', random.nextInt(100)),
|
||||
OrdinalSales('2027', random.nextInt(100)),
|
||||
OrdinalSales('2028', random.nextInt(100)),
|
||||
OrdinalSales('2029', random.nextInt(100)),
|
||||
OrdinalSales('2030', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
@@ -108,7 +109,7 @@ class InitialHintAnimation extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
// Optionally turn off the animation that animates values up from the
|
||||
@@ -117,17 +118,17 @@ class InitialHintAnimation extends StatelessWidget {
|
||||
animationDuration: Duration.zero,
|
||||
// Set the initial viewport by providing a new AxisSpec with the
|
||||
// desired viewport: a starting domain and the data size.
|
||||
domainAxis: new charts.OrdinalAxisSpec(
|
||||
viewport: new charts.OrdinalViewport('2018', 4)),
|
||||
domainAxis:
|
||||
charts.OrdinalAxisSpec(viewport: charts.OrdinalViewport('2018', 4)),
|
||||
behaviors: [
|
||||
// Add this behavior to show initial hint animation that will pan to the
|
||||
// final desired viewport.
|
||||
// The duration of the animation can be adjusted by pass in
|
||||
// [hintDuration]. By default this is 3000ms.
|
||||
new charts.InitialHintBehavior(maxHintTranslate: 4.0),
|
||||
charts.InitialHintBehavior(maxHintTranslate: 4.0),
|
||||
// Optionally add a pan or pan and zoom behavior.
|
||||
// If pan/zoom is not added, the viewport specified remains the viewport
|
||||
new charts.PanAndZoomBehavior(),
|
||||
charts.PanAndZoomBehavior(),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -135,27 +136,27 @@ class InitialHintAnimation extends StatelessWidget {
|
||||
/// 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),
|
||||
new OrdinalSales('2018', 33),
|
||||
new OrdinalSales('2019', 80),
|
||||
new OrdinalSales('2020', 21),
|
||||
new OrdinalSales('2021', 77),
|
||||
new OrdinalSales('2022', 8),
|
||||
new OrdinalSales('2023', 12),
|
||||
new OrdinalSales('2024', 42),
|
||||
new OrdinalSales('2025', 70),
|
||||
new OrdinalSales('2026', 77),
|
||||
new OrdinalSales('2027', 55),
|
||||
new OrdinalSales('2028', 19),
|
||||
new OrdinalSales('2029', 66),
|
||||
new OrdinalSales('2030', 27),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
OrdinalSales('2018', 33),
|
||||
OrdinalSales('2019', 80),
|
||||
OrdinalSales('2020', 21),
|
||||
OrdinalSales('2021', 77),
|
||||
OrdinalSales('2022', 8),
|
||||
OrdinalSales('2023', 12),
|
||||
OrdinalSales('2024', 42),
|
||||
OrdinalSales('2025', 70),
|
||||
OrdinalSales('2026', 77),
|
||||
OrdinalSales('2027', 55),
|
||||
OrdinalSales('2028', 19),
|
||||
OrdinalSales('2029', 66),
|
||||
OrdinalSales('2030', 27),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
|
||||
@@ -34,11 +34,12 @@ class InitialSelection extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
InitialSelection(this.seriesList, {this.animate});
|
||||
const InitialSelection(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [BarChart] with initial selection behavior.
|
||||
factory InitialSelection.withSampleData() {
|
||||
return new InitialSelection(
|
||||
return InitialSelection(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -50,22 +51,22 @@ class InitialSelection extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory InitialSelection.withRandomData() {
|
||||
return new InitialSelection(_createRandomData());
|
||||
return InitialSelection(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
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: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
@@ -78,7 +79,7 @@ class InitialSelection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
behaviors: [
|
||||
@@ -92,8 +93,8 @@ class InitialSelection extends StatelessWidget {
|
||||
// [BarChart] by default includes behaviors [SelectNearest] and
|
||||
// [DomainHighlighter]. So this behavior shows the initial selection
|
||||
// highlighted and when another datum is tapped, the selection changes.
|
||||
new charts.InitialSelection(selectedDataConfig: [
|
||||
new charts.SeriesDatumConfig<String>('Sales', '2016')
|
||||
charts.InitialSelection(selectedDataConfig: [
|
||||
charts.SeriesDatumConfig<String>('Sales', '2016')
|
||||
])
|
||||
],
|
||||
);
|
||||
@@ -102,14 +103,14 @@ class InitialSelection extends StatelessWidget {
|
||||
/// 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),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
|
||||
@@ -27,11 +27,12 @@ class PercentOfDomainBarChart extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
PercentOfDomainBarChart(this.seriesList, {this.animate});
|
||||
const PercentOfDomainBarChart(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a stacked [BarChart] with sample data and no transition.
|
||||
factory PercentOfDomainBarChart.withSampleData() {
|
||||
return new PercentOfDomainBarChart(
|
||||
return PercentOfDomainBarChart(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -43,48 +44,48 @@ class PercentOfDomainBarChart extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory PercentOfDomainBarChart.withRandomData() {
|
||||
return new PercentOfDomainBarChart(_createRandomData());
|
||||
return PercentOfDomainBarChart(_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 tableSalesData = [
|
||||
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)),
|
||||
];
|
||||
|
||||
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: tableSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -96,7 +97,7 @@ class PercentOfDomainBarChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.stacked,
|
||||
@@ -104,51 +105,51 @@ class PercentOfDomainBarChart extends StatelessWidget {
|
||||
// values as the percentage of the total of all data that shares a
|
||||
// domain value.
|
||||
behaviors: [
|
||||
new charts.PercentInjector(
|
||||
charts.PercentInjector(
|
||||
totalType: charts.PercentInjectorTotalType.domain)
|
||||
],
|
||||
// Configure the axis spec to show percentage values.
|
||||
primaryMeasureAxis: new charts.PercentAxisSpec(),
|
||||
primaryMeasureAxis: charts.PercentAxisSpec(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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 tableSalesData = [
|
||||
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),
|
||||
];
|
||||
|
||||
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: tableSalesData,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -28,10 +28,12 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
PercentOfDomainByCategoryBarChart(this.seriesList, {this.animate});
|
||||
const PercentOfDomainByCategoryBarChart(this.seriesList,
|
||||
{this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
factory PercentOfDomainByCategoryBarChart.withSampleData() {
|
||||
return new PercentOfDomainByCategoryBarChart(
|
||||
return PercentOfDomainByCategoryBarChart(
|
||||
createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -43,92 +45,92 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory PercentOfDomainByCategoryBarChart.withRandomData() {
|
||||
return new PercentOfDomainByCategoryBarChart(_createRandomData());
|
||||
return PercentOfDomainByCategoryBarChart(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final desktopSalesDataA = [
|
||||
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 tableSalesDataA = [
|
||||
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 mobileSalesDataA = [
|
||||
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 desktopSalesDataB = [
|
||||
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 tableSalesDataB = [
|
||||
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 mobileSalesDataB = [
|
||||
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 A',
|
||||
seriesCategory: 'A',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesDataA,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet A',
|
||||
seriesCategory: 'A',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tableSalesDataA,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile A',
|
||||
seriesCategory: 'A',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesDataA,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop B',
|
||||
seriesCategory: 'B',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesDataB,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet B',
|
||||
seriesCategory: 'B',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tableSalesDataB,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile B',
|
||||
seriesCategory: 'B',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
@@ -141,7 +143,7 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.groupedStacked,
|
||||
@@ -153,95 +155,95 @@ class PercentOfDomainByCategoryBarChart extends StatelessWidget {
|
||||
// total value for each bar stack is 100%. A stacked bar chart that does
|
||||
// not group by series category would use the "domain" option.
|
||||
behaviors: [
|
||||
new charts.PercentInjector(
|
||||
charts.PercentInjector(
|
||||
totalType: charts.PercentInjectorTotalType.domainBySeriesCategory)
|
||||
],
|
||||
// Configure the axis spec to show percentage values.
|
||||
primaryMeasureAxis: new charts.PercentAxisSpec(),
|
||||
primaryMeasureAxis: charts.PercentAxisSpec(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> createSampleData() {
|
||||
final desktopSalesDataA = [
|
||||
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 tableSalesDataA = [
|
||||
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 mobileSalesDataA = [
|
||||
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 desktopSalesDataB = [
|
||||
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 tableSalesDataB = [
|
||||
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 mobileSalesDataB = [
|
||||
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),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop A',
|
||||
seriesCategory: 'A',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesDataA,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet A',
|
||||
seriesCategory: 'A',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tableSalesDataA,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile A',
|
||||
seriesCategory: 'A',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: mobileSalesDataA,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop B',
|
||||
seriesCategory: 'B',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: desktopSalesDataB,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Tablet B',
|
||||
seriesCategory: 'B',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: tableSalesDataB,
|
||||
),
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Mobile B',
|
||||
seriesCategory: 'B',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
|
||||
@@ -25,11 +25,12 @@ class PercentOfSeriesBarChart extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
PercentOfSeriesBarChart(this.seriesList, {this.animate});
|
||||
const PercentOfSeriesBarChart(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a stacked [BarChart] with sample data and no transition.
|
||||
factory PercentOfSeriesBarChart.withSampleData() {
|
||||
return new PercentOfSeriesBarChart(
|
||||
return PercentOfSeriesBarChart(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -41,26 +42,26 @@ class PercentOfSeriesBarChart extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory PercentOfSeriesBarChart.withRandomData() {
|
||||
return new PercentOfSeriesBarChart(_createRandomData());
|
||||
return PercentOfSeriesBarChart(_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)),
|
||||
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)),
|
||||
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,
|
||||
@@ -72,36 +73,36 @@ class PercentOfSeriesBarChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
barGroupingType: charts.BarGroupingType.grouped,
|
||||
// Configures a [PercentInjector] behavior that will calculate measure
|
||||
// values as the percentage of the total of all data in its series.
|
||||
behaviors: [
|
||||
new charts.PercentInjector(
|
||||
charts.PercentInjector(
|
||||
totalType: charts.PercentInjectorTotalType.series)
|
||||
],
|
||||
// Configure the axis spec to show percentage values.
|
||||
primaryMeasureAxis: new charts.PercentAxisSpec(),
|
||||
primaryMeasureAxis: charts.PercentAxisSpec(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Create series list with multiple series
|
||||
static List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final desktopSalesData = [
|
||||
new OrdinalSales('2011', 5),
|
||||
new OrdinalSales('2012', 25),
|
||||
new OrdinalSales('2013', 50),
|
||||
new OrdinalSales('2014', 75),
|
||||
new OrdinalSales('2015', 100),
|
||||
new OrdinalSales('2016', 125),
|
||||
new OrdinalSales('2017', 200),
|
||||
new OrdinalSales('2018', 150),
|
||||
OrdinalSales('2011', 5),
|
||||
OrdinalSales('2012', 25),
|
||||
OrdinalSales('2013', 50),
|
||||
OrdinalSales('2014', 75),
|
||||
OrdinalSales('2015', 100),
|
||||
OrdinalSales('2016', 125),
|
||||
OrdinalSales('2017', 200),
|
||||
OrdinalSales('2018', 150),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Desktop',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -22,11 +22,12 @@ class SelectionBarHighlight extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SelectionBarHighlight(this.seriesList, {this.animate});
|
||||
const SelectionBarHighlight(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [BarChart] with sample data and no transition.
|
||||
factory SelectionBarHighlight.withSampleData() {
|
||||
return new SelectionBarHighlight(
|
||||
return SelectionBarHighlight(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -38,22 +39,22 @@ class SelectionBarHighlight extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SelectionBarHighlight.withRandomData() {
|
||||
return new SelectionBarHighlight(_createRandomData());
|
||||
return SelectionBarHighlight(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
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: 'Sales',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
@@ -74,7 +75,7 @@ class SelectionBarHighlight extends StatelessWidget {
|
||||
//
|
||||
// [defaultInteractions] can be set to false to avoid the default
|
||||
// interactions.
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
defaultInteractions: true,
|
||||
@@ -84,14 +85,14 @@ class SelectionBarHighlight extends StatelessWidget {
|
||||
/// 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),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
|
||||
@@ -36,11 +36,12 @@ class SelectionCallbackExample extends StatefulWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SelectionCallbackExample(this.seriesList, {this.animate});
|
||||
const SelectionCallbackExample(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [charts.TimeSeriesChart] with sample data and no transition.
|
||||
factory SelectionCallbackExample.withSampleData() {
|
||||
return new SelectionCallbackExample(
|
||||
return SelectionCallbackExample(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -52,35 +53,35 @@ class SelectionCallbackExample extends StatefulWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SelectionCallbackExample.withRandomData() {
|
||||
return new SelectionCallbackExample(_createRandomData());
|
||||
return SelectionCallbackExample(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<TimeSeriesSales, DateTime>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final usData = [
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)),
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)),
|
||||
];
|
||||
|
||||
final ukData = [
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 19), random.nextInt(100)),
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 26), random.nextInt(100)),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 3), random.nextInt(100)),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 10), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 9, 19), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 9, 26), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 10, 3), random.nextInt(100)),
|
||||
TimeSeriesSales(DateTime(2017, 10, 10), random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<TimeSeriesSales, DateTime>(
|
||||
charts.Series<TimeSeriesSales, DateTime>(
|
||||
id: 'US Sales',
|
||||
domainFn: (TimeSeriesSales sales, _) => sales.time,
|
||||
measureFn: (TimeSeriesSales sales, _) => sales.sales,
|
||||
data: usData,
|
||||
),
|
||||
new charts.Series<TimeSeriesSales, DateTime>(
|
||||
charts.Series<TimeSeriesSales, DateTime>(
|
||||
id: 'UK Sales',
|
||||
domainFn: (TimeSeriesSales sales, _) => sales.time,
|
||||
measureFn: (TimeSeriesSales sales, _) => sales.sales,
|
||||
@@ -93,32 +94,32 @@ class SelectionCallbackExample extends StatefulWidget {
|
||||
// We need a Stateful widget to build the selection details with the current
|
||||
// selection as the state.
|
||||
@override
|
||||
State<StatefulWidget> createState() => new _SelectionCallbackState();
|
||||
State<StatefulWidget> createState() => _SelectionCallbackState();
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<TimeSeriesSales, DateTime>> _createSampleData() {
|
||||
final usData = [
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 19), 5),
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 26), 25),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 3), 78),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 10), 54),
|
||||
TimeSeriesSales(DateTime(2017, 9, 19), 5),
|
||||
TimeSeriesSales(DateTime(2017, 9, 26), 25),
|
||||
TimeSeriesSales(DateTime(2017, 10, 3), 78),
|
||||
TimeSeriesSales(DateTime(2017, 10, 10), 54),
|
||||
];
|
||||
|
||||
final ukData = [
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 19), 15),
|
||||
new TimeSeriesSales(new DateTime(2017, 9, 26), 33),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 3), 68),
|
||||
new TimeSeriesSales(new DateTime(2017, 10, 10), 48),
|
||||
TimeSeriesSales(DateTime(2017, 9, 19), 15),
|
||||
TimeSeriesSales(DateTime(2017, 9, 26), 33),
|
||||
TimeSeriesSales(DateTime(2017, 10, 3), 68),
|
||||
TimeSeriesSales(DateTime(2017, 10, 10), 48),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<TimeSeriesSales, DateTime>(
|
||||
charts.Series<TimeSeriesSales, DateTime>(
|
||||
id: 'US Sales',
|
||||
domainFn: (TimeSeriesSales sales, _) => sales.time,
|
||||
measureFn: (TimeSeriesSales sales, _) => sales.sales,
|
||||
data: usData,
|
||||
),
|
||||
new charts.Series<TimeSeriesSales, DateTime>(
|
||||
charts.Series<TimeSeriesSales, DateTime>(
|
||||
id: 'UK Sales',
|
||||
domainFn: (TimeSeriesSales sales, _) => sales.time,
|
||||
measureFn: (TimeSeriesSales sales, _) => sales.sales,
|
||||
@@ -148,9 +149,9 @@ class _SelectionCallbackState extends State<SelectionCallbackExample> {
|
||||
// series name for each selection point.
|
||||
if (selectedDatum.isNotEmpty) {
|
||||
time = selectedDatum.first.datum.time;
|
||||
selectedDatum.forEach((charts.SeriesDatum datumPair) {
|
||||
for (var datumPair in selectedDatum) {
|
||||
measures[datumPair.series.displayName] = datumPair.datum.sales;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Request a build.
|
||||
@@ -164,13 +165,13 @@ class _SelectionCallbackState extends State<SelectionCallbackExample> {
|
||||
Widget build(BuildContext context) {
|
||||
// The children consist of a Chart and Text widgets below to hold the info.
|
||||
final children = <Widget>[
|
||||
new SizedBox(
|
||||
SizedBox(
|
||||
height: 150.0,
|
||||
child: new charts.TimeSeriesChart(
|
||||
child: charts.TimeSeriesChart(
|
||||
widget.seriesList,
|
||||
animate: widget.animate,
|
||||
selectionModels: [
|
||||
new charts.SelectionModelConfig(
|
||||
charts.SelectionModelConfig(
|
||||
type: charts.SelectionModelType.info,
|
||||
changedListener: _onSelectionChanged,
|
||||
)
|
||||
@@ -180,15 +181,15 @@ class _SelectionCallbackState extends State<SelectionCallbackExample> {
|
||||
|
||||
// If there is a selection, then include the details.
|
||||
if (_time != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text(_time.toString())));
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text(_time.toString())));
|
||||
}
|
||||
_measures?.forEach((String series, num value) {
|
||||
children.add(new Text('$series: $value'));
|
||||
children.add(Text('$series: $value'));
|
||||
});
|
||||
|
||||
return new Column(children: children);
|
||||
return Column(children: children);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,12 @@ class SelectionLineHighlight extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SelectionLineHighlight(this.seriesList, {this.animate});
|
||||
const SelectionLineHighlight(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [LineChart] with sample data and no transition.
|
||||
factory SelectionLineHighlight.withSampleData() {
|
||||
return new SelectionLineHighlight(
|
||||
return SelectionLineHighlight(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -38,22 +39,22 @@ class SelectionLineHighlight extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SelectionLineHighlight.withRandomData() {
|
||||
return new SelectionLineHighlight(_createRandomData());
|
||||
return SelectionLineHighlight(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, num>> _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,
|
||||
@@ -75,7 +76,7 @@ class SelectionLineHighlight extends StatelessWidget {
|
||||
//
|
||||
// As an alternative, [defaultInteractions] can be set to true to include
|
||||
// the default chart interactions, including a LinePointHighlighter.
|
||||
return new charts.LineChart(seriesList, animate: animate, behaviors: [
|
||||
return charts.LineChart(seriesList, animate: animate, behaviors: [
|
||||
// Optional - Configures a [LinePointHighlighter] behavior with a
|
||||
// vertical follow line. A vertical follow line is included by
|
||||
// default, but is shown here as an example configuration.
|
||||
@@ -84,7 +85,7 @@ class SelectionLineHighlight extends StatelessWidget {
|
||||
// set by providing a [dashPattern] or it can be turned off by passing in
|
||||
// an empty list. An empty list is necessary because passing in a null
|
||||
// value will be treated the same as not passing in a value at all.
|
||||
new charts.LinePointHighlighter(
|
||||
charts.LinePointHighlighter(
|
||||
showHorizontalFollowLine:
|
||||
charts.LinePointHighlighterFollowLineType.none,
|
||||
showVerticalFollowLine:
|
||||
@@ -94,21 +95,21 @@ class SelectionLineHighlight extends StatelessWidget {
|
||||
// highlighter. Changing the trigger to tap and drag allows the
|
||||
// highlighter to follow the dragging gesture but it is not
|
||||
// recommended to be used when pan/zoom behavior is enabled.
|
||||
new charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag)
|
||||
charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag)
|
||||
]);
|
||||
}
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 5),
|
||||
new LinearSales(1, 25),
|
||||
new LinearSales(2, 100),
|
||||
new LinearSales(3, 75),
|
||||
LinearSales(0, 5),
|
||||
LinearSales(1, 25),
|
||||
LinearSales(2, 100),
|
||||
LinearSales(3, 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
@@ -22,11 +22,13 @@ class SelectionLineHighlightCustomShape extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SelectionLineHighlightCustomShape(this.seriesList, {this.animate});
|
||||
const SelectionLineHighlightCustomShape(this.seriesList,
|
||||
{this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [LineChart] with sample data and no transition.
|
||||
factory SelectionLineHighlightCustomShape.withSampleData() {
|
||||
return new SelectionLineHighlightCustomShape(
|
||||
return SelectionLineHighlightCustomShape(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -38,22 +40,22 @@ class SelectionLineHighlightCustomShape extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SelectionLineHighlightCustomShape.withRandomData() {
|
||||
return new SelectionLineHighlightCustomShape(_createRandomData());
|
||||
return SelectionLineHighlightCustomShape(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, num>> _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,
|
||||
@@ -74,7 +76,7 @@ class SelectionLineHighlightCustomShape extends StatelessWidget {
|
||||
//
|
||||
// As an alternative, [defaultInteractions] can be set to true to include
|
||||
// the default chart interactions, including a LinePointHighlighter.
|
||||
return new charts.LineChart(seriesList, animate: animate, behaviors: [
|
||||
return charts.LineChart(seriesList, animate: animate, behaviors: [
|
||||
// Optional - Configures a [LinePointHighlighter] behavior with a
|
||||
// vertical follow line. A vertical follow line is included by
|
||||
// default, but is shown here as an example configuration.
|
||||
@@ -86,32 +88,32 @@ class SelectionLineHighlightCustomShape extends StatelessWidget {
|
||||
//
|
||||
// The symbol renderer is configured to render a hollow shape, for
|
||||
// demonstration.
|
||||
new charts.LinePointHighlighter(
|
||||
charts.LinePointHighlighter(
|
||||
showHorizontalFollowLine:
|
||||
charts.LinePointHighlighterFollowLineType.none,
|
||||
showVerticalFollowLine:
|
||||
charts.LinePointHighlighterFollowLineType.nearest,
|
||||
symbolRenderer: new charts.RectSymbolRenderer(isSolid: false)),
|
||||
symbolRenderer: charts.RectSymbolRenderer(isSolid: false)),
|
||||
// Optional - By default, select nearest is configured to trigger
|
||||
// with tap so that a user can have pan/zoom behavior and line point
|
||||
// highlighter. Changing the trigger to tap and drag allows the
|
||||
// highlighter to follow the dragging gesture but it is not
|
||||
// recommended to be used when pan/zoom behavior is enabled.
|
||||
new charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag)
|
||||
charts.SelectNearest(eventTrigger: charts.SelectionTrigger.tapAndDrag)
|
||||
]);
|
||||
}
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 5),
|
||||
new LinearSales(1, 25),
|
||||
new LinearSales(2, 100),
|
||||
new LinearSales(3, 75),
|
||||
LinearSales(0, 5),
|
||||
LinearSales(1, 25),
|
||||
LinearSales(2, 100),
|
||||
LinearSales(3, 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
|
||||
@@ -41,11 +41,12 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SelectionScatterPlotHighlight(this.seriesList, {this.animate});
|
||||
const SelectionScatterPlotHighlight(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [ScatterPlotChart] with sample data and no transition.
|
||||
factory SelectionScatterPlotHighlight.withSampleData() {
|
||||
return new SelectionScatterPlotHighlight(
|
||||
return SelectionScatterPlotHighlight(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -57,49 +58,49 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SelectionScatterPlotHighlight.withRandomData() {
|
||||
return new SelectionScatterPlotHighlight(_createRandomData());
|
||||
return SelectionScatterPlotHighlight(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, num>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final makeRadius = (int value) => (random.nextInt(value) + 2).toDouble();
|
||||
makeRadius(int value) => (random.nextInt(value) + 2).toDouble();
|
||||
|
||||
final data = [
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
'circle', null, null),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
// Render a hollow circle, filled in with white.
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100),
|
||||
makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(4) + 4,
|
||||
'circle', charts.MaterialPalette.white, 2.0),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
'circle', null, null),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
// Render a hollow circle, filled in with white.
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100),
|
||||
makeRadius(4) + 4, 'circle', charts.MaterialPalette.white, 2.0),
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6),
|
||||
null, null, null),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(4) + 4,
|
||||
'circle', charts.MaterialPalette.white, 2.0),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(6), null,
|
||||
null, null),
|
||||
// Render a hollow square, filled in with white.
|
||||
new LinearSales(random.nextInt(100), random.nextInt(100),
|
||||
makeRadius(4) + 4, null, charts.MaterialPalette.white, 2.0),
|
||||
LinearSales(random.nextInt(100), random.nextInt(100), makeRadius(4) + 4,
|
||||
null, charts.MaterialPalette.white, 2.0),
|
||||
];
|
||||
|
||||
final maxMeasure = 100;
|
||||
const maxMeasure = 100;
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
colorFn: (LinearSales sales, _) {
|
||||
// Color bucket the measure column value into 3 distinct colors.
|
||||
@@ -131,7 +132,7 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.ScatterPlotChart(seriesList,
|
||||
return charts.ScatterPlotChart(seriesList,
|
||||
animate: animate,
|
||||
behaviors: [
|
||||
// Optional - Configures a [LinePointHighlighter] behavior with
|
||||
@@ -143,7 +144,7 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
|
||||
// in an empty list. An empty list is necessary because passing in a
|
||||
// null value will be treated the same as not passing in a value at
|
||||
// all.
|
||||
new charts.LinePointHighlighter(
|
||||
charts.LinePointHighlighter(
|
||||
showHorizontalFollowLine:
|
||||
charts.LinePointHighlighterFollowLineType.nearest,
|
||||
showVerticalFollowLine:
|
||||
@@ -153,44 +154,42 @@ class SelectionScatterPlotHighlight extends StatelessWidget {
|
||||
// highlighter. Changing the trigger to tap and drag allows the
|
||||
// highlighter to follow the dragging gesture but it is not
|
||||
// recommended to be used when pan/zoom behavior is enabled.
|
||||
new charts.SelectNearest(
|
||||
charts.SelectNearest(
|
||||
eventTrigger: charts.SelectionTrigger.tapAndDrag),
|
||||
],
|
||||
// Configure the point renderer to have a map of custom symbol
|
||||
// renderers.
|
||||
defaultRenderer:
|
||||
new charts.PointRendererConfig<num>(customSymbolRenderers: {
|
||||
'circle': new charts.CircleSymbolRenderer(),
|
||||
'rect': new charts.RectSymbolRenderer(),
|
||||
charts.PointRendererConfig<num>(customSymbolRenderers: {
|
||||
'circle': charts.CircleSymbolRenderer(),
|
||||
'rect': charts.RectSymbolRenderer(),
|
||||
}));
|
||||
}
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 5, 3.0, 'circle', null, null),
|
||||
new LinearSales(10, 25, 5.0, null, null, null),
|
||||
new LinearSales(12, 75, 4.0, null, null, null),
|
||||
LinearSales(0, 5, 3.0, 'circle', null, null),
|
||||
LinearSales(10, 25, 5.0, null, null, null),
|
||||
LinearSales(12, 75, 4.0, null, null, null),
|
||||
// Render a hollow circle, filled in with white.
|
||||
new LinearSales(
|
||||
13, 225, 5.0, 'circle', charts.MaterialPalette.white, 2.0),
|
||||
new LinearSales(16, 50, 4.0, null, null, null),
|
||||
new LinearSales(24, 75, 3.0, null, null, null),
|
||||
new LinearSales(25, 100, 3.0, 'circle', null, null),
|
||||
new LinearSales(34, 150, 5.0, null, null, null),
|
||||
new LinearSales(37, 10, 4.5, null, null, null),
|
||||
LinearSales(13, 225, 5.0, 'circle', charts.MaterialPalette.white, 2.0),
|
||||
LinearSales(16, 50, 4.0, null, null, null),
|
||||
LinearSales(24, 75, 3.0, null, null, null),
|
||||
LinearSales(25, 100, 3.0, 'circle', null, null),
|
||||
LinearSales(34, 150, 5.0, null, null, null),
|
||||
LinearSales(37, 10, 4.5, null, null, null),
|
||||
// Render a hollow circle, filled in with white.
|
||||
new LinearSales(
|
||||
45, 300, 8.0, 'circle', charts.MaterialPalette.white, 2.0),
|
||||
new LinearSales(52, 15, 4.0, null, null, null),
|
||||
LinearSales(45, 300, 8.0, 'circle', charts.MaterialPalette.white, 2.0),
|
||||
LinearSales(52, 15, 4.0, null, null, null),
|
||||
// Render a hollow square, filled in with white.
|
||||
new LinearSales(56, 200, 7.0, null, charts.MaterialPalette.white, 2.0),
|
||||
LinearSales(56, 200, 7.0, null, charts.MaterialPalette.white, 2.0),
|
||||
];
|
||||
|
||||
final maxMeasure = 300;
|
||||
const maxMeasure = 300;
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
// Providing a color function is optional.
|
||||
colorFn: (LinearSales sales, _) {
|
||||
|
||||
@@ -32,11 +32,12 @@ class SelectionUserManaged extends StatefulWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SelectionUserManaged(this.seriesList, {this.animate});
|
||||
const SelectionUserManaged(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [BarChart] with sample data and no transition.
|
||||
factory SelectionUserManaged.withSampleData() {
|
||||
return new SelectionUserManaged(
|
||||
return SelectionUserManaged(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -48,22 +49,22 @@ class SelectionUserManaged extends StatefulWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SelectionUserManaged.withRandomData() {
|
||||
return new SelectionUserManaged(_createRandomData());
|
||||
return SelectionUserManaged(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
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: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
@@ -77,14 +78,14 @@ class SelectionUserManaged extends StatefulWidget {
|
||||
/// 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),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
@@ -96,20 +97,20 @@ class SelectionUserManaged extends StatefulWidget {
|
||||
|
||||
@override
|
||||
SelectionUserManagedState createState() {
|
||||
return new SelectionUserManagedState();
|
||||
return SelectionUserManagedState();
|
||||
}
|
||||
}
|
||||
|
||||
class SelectionUserManagedState extends State<SelectionUserManaged> {
|
||||
final _myState = new charts.UserManagedState<String>();
|
||||
final _myState = charts.UserManagedState<String>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final chart = new charts.BarChart(
|
||||
final chart = charts.BarChart(
|
||||
widget.seriesList,
|
||||
animate: false, //widget.animate,
|
||||
selectionModels: [
|
||||
new charts.SelectionModelConfig(
|
||||
charts.SelectionModelConfig(
|
||||
type: charts.SelectionModelType.info,
|
||||
updatedListener: _infoSelectionModelUpdated)
|
||||
],
|
||||
@@ -119,17 +120,17 @@ class SelectionUserManagedState extends State<SelectionUserManaged> {
|
||||
// The initial selection can still be optionally added by adding the
|
||||
// initial selection behavior.
|
||||
behaviors: [
|
||||
new charts.InitialSelection(selectedDataConfig: [
|
||||
new charts.SeriesDatumConfig<String>('Sales', '2016')
|
||||
charts.InitialSelection(selectedDataConfig: [
|
||||
charts.SeriesDatumConfig<String>('Sales', '2016')
|
||||
])
|
||||
],
|
||||
);
|
||||
|
||||
final clearSelection = new MaterialButton(
|
||||
onPressed: _handleClearSelection, child: new Text('Clear Selection'));
|
||||
final clearSelection = MaterialButton(
|
||||
onPressed: _handleClearSelection, child: const Text('Clear Selection'));
|
||||
|
||||
return new Column(
|
||||
children: [new SizedBox(child: chart, height: 150.0), clearSelection]);
|
||||
return Column(
|
||||
children: [SizedBox(child: chart, height: 150.0), clearSelection]);
|
||||
}
|
||||
|
||||
void _infoSelectionModelUpdated(charts.SelectionModel<String> model) {
|
||||
@@ -141,7 +142,7 @@ class SelectionUserManagedState extends State<SelectionUserManaged> {
|
||||
// This also allows you to listen to the selection model update events and
|
||||
// alter the selection.
|
||||
_myState.selectionModels[charts.SelectionModelType.info] =
|
||||
new charts.UserManagedSelectionModel(model: model);
|
||||
charts.UserManagedSelectionModel(model: model);
|
||||
}
|
||||
|
||||
void _handleClearSelection() {
|
||||
@@ -150,7 +151,7 @@ class SelectionUserManagedState extends State<SelectionUserManaged> {
|
||||
// no selection model to clear all selection when rebuilt.
|
||||
setState(() {
|
||||
_myState.selectionModels[charts.SelectionModelType.info] =
|
||||
new charts.UserManagedSelectionModel();
|
||||
charts.UserManagedSelectionModel();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ class SliderLine extends StatefulWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SliderLine(this.seriesList, {this.animate});
|
||||
const SliderLine(this.seriesList, {this.animate, Key key}) : super(key: key);
|
||||
|
||||
/// Creates a [LineChart] with sample data and no transition.
|
||||
factory SliderLine.withSampleData() {
|
||||
return new SliderLine(
|
||||
return SliderLine(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -52,22 +52,22 @@ class SliderLine extends StatefulWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SliderLine.withRandomData() {
|
||||
return new SliderLine(_createRandomData());
|
||||
return SliderLine(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, num>> _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,
|
||||
@@ -80,19 +80,19 @@ class SliderLine extends StatefulWidget {
|
||||
// We need a Stateful widget to build the selection details with the current
|
||||
// selection as the state.
|
||||
@override
|
||||
State<StatefulWidget> createState() => new _SliderCallbackState();
|
||||
State<StatefulWidget> createState() => _SliderCallbackState();
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 5),
|
||||
new LinearSales(1, 25),
|
||||
new LinearSales(2, 100),
|
||||
new LinearSales(3, 75),
|
||||
LinearSales(0, 5),
|
||||
LinearSales(1, 25),
|
||||
LinearSales(2, 100),
|
||||
LinearSales(3, 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -126,9 +126,9 @@ class _SliderCallbackState extends State<SliderLine> {
|
||||
Widget build(BuildContext context) {
|
||||
// The children consist of a Chart and Text widgets below to hold the info.
|
||||
final children = <Widget>[
|
||||
new SizedBox(
|
||||
SizedBox(
|
||||
height: 150.0,
|
||||
child: new charts.LineChart(
|
||||
child: charts.LineChart(
|
||||
widget.seriesList,
|
||||
animate: widget.animate,
|
||||
// Configures a [Slider] behavior.
|
||||
@@ -159,7 +159,7 @@ class _SliderCallbackState extends State<SliderLine> {
|
||||
// [style] takes in a [SliderStyle] configuration object, and
|
||||
// configures the color and sizing of the slider line and handle.
|
||||
behaviors: [
|
||||
new charts.Slider(
|
||||
charts.Slider(
|
||||
initialDomainValue: 1.0, onChangeCallback: _onSliderChange),
|
||||
],
|
||||
)),
|
||||
@@ -167,23 +167,23 @@ class _SliderCallbackState extends State<SliderLine> {
|
||||
|
||||
// If there is a slider change event, then include the details.
|
||||
if (_sliderDomainValue != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text('Slider domain value: $_sliderDomainValue')));
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text('Slider domain value: $_sliderDomainValue')));
|
||||
}
|
||||
if (_sliderPosition != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text(
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text(
|
||||
'Slider position: ${_sliderPosition.x}, ${_sliderPosition.y}')));
|
||||
}
|
||||
if (_sliderDragState != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text('Slider drag state: $_sliderDragState')));
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text('Slider drag state: $_sliderDragState')));
|
||||
}
|
||||
|
||||
return new Column(children: children);
|
||||
return Column(children: children);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,12 @@ class SlidingViewportOnSelection extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SlidingViewportOnSelection(this.seriesList, {this.animate});
|
||||
const SlidingViewportOnSelection(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [BarChart] with sample data and no transition.
|
||||
factory SlidingViewportOnSelection.withSampleData() {
|
||||
return new SlidingViewportOnSelection(
|
||||
return SlidingViewportOnSelection(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -41,35 +42,35 @@ class SlidingViewportOnSelection extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SlidingViewportOnSelection.withRandomData() {
|
||||
return new SlidingViewportOnSelection(_createRandomData());
|
||||
return SlidingViewportOnSelection(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<OrdinalSales, String>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new OrdinalSales('2014', random.nextInt(100)),
|
||||
new OrdinalSales('2015', random.nextInt(100)),
|
||||
new OrdinalSales('2016', random.nextInt(100)),
|
||||
new OrdinalSales('2017', random.nextInt(100)),
|
||||
new OrdinalSales('2018', random.nextInt(100)),
|
||||
new OrdinalSales('2019', random.nextInt(100)),
|
||||
new OrdinalSales('2020', random.nextInt(100)),
|
||||
new OrdinalSales('2021', random.nextInt(100)),
|
||||
new OrdinalSales('2022', random.nextInt(100)),
|
||||
new OrdinalSales('2023', random.nextInt(100)),
|
||||
new OrdinalSales('2024', random.nextInt(100)),
|
||||
new OrdinalSales('2025', random.nextInt(100)),
|
||||
new OrdinalSales('2026', random.nextInt(100)),
|
||||
new OrdinalSales('2027', random.nextInt(100)),
|
||||
new OrdinalSales('2028', random.nextInt(100)),
|
||||
new OrdinalSales('2029', random.nextInt(100)),
|
||||
new OrdinalSales('2030', random.nextInt(100)),
|
||||
OrdinalSales('2014', random.nextInt(100)),
|
||||
OrdinalSales('2015', random.nextInt(100)),
|
||||
OrdinalSales('2016', random.nextInt(100)),
|
||||
OrdinalSales('2017', random.nextInt(100)),
|
||||
OrdinalSales('2018', random.nextInt(100)),
|
||||
OrdinalSales('2019', random.nextInt(100)),
|
||||
OrdinalSales('2020', random.nextInt(100)),
|
||||
OrdinalSales('2021', random.nextInt(100)),
|
||||
OrdinalSales('2022', random.nextInt(100)),
|
||||
OrdinalSales('2023', random.nextInt(100)),
|
||||
OrdinalSales('2024', random.nextInt(100)),
|
||||
OrdinalSales('2025', random.nextInt(100)),
|
||||
OrdinalSales('2026', random.nextInt(100)),
|
||||
OrdinalSales('2027', random.nextInt(100)),
|
||||
OrdinalSales('2028', random.nextInt(100)),
|
||||
OrdinalSales('2029', random.nextInt(100)),
|
||||
OrdinalSales('2030', random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
@@ -82,49 +83,49 @@ class SlidingViewportOnSelection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new charts.BarChart(
|
||||
return charts.BarChart(
|
||||
seriesList,
|
||||
animate: animate,
|
||||
behaviors: [
|
||||
// Add the sliding viewport behavior to have the viewport center on the
|
||||
// domain that is currently selected.
|
||||
new charts.SlidingViewport(),
|
||||
charts.SlidingViewport(),
|
||||
// A pan and zoom behavior helps demonstrate the sliding viewport
|
||||
// behavior by allowing the data visible in the viewport to be adjusted
|
||||
// dynamically.
|
||||
new charts.PanAndZoomBehavior(),
|
||||
charts.PanAndZoomBehavior(),
|
||||
],
|
||||
// Set an initial viewport to demonstrate the sliding viewport behavior on
|
||||
// initial chart load.
|
||||
domainAxis: new charts.OrdinalAxisSpec(
|
||||
viewport: new charts.OrdinalViewport('2018', 4)),
|
||||
domainAxis:
|
||||
charts.OrdinalAxisSpec(viewport: charts.OrdinalViewport('2018', 4)),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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),
|
||||
new OrdinalSales('2018', 33),
|
||||
new OrdinalSales('2019', 80),
|
||||
new OrdinalSales('2020', 21),
|
||||
new OrdinalSales('2021', 77),
|
||||
new OrdinalSales('2022', 8),
|
||||
new OrdinalSales('2023', 12),
|
||||
new OrdinalSales('2024', 42),
|
||||
new OrdinalSales('2025', 70),
|
||||
new OrdinalSales('2026', 77),
|
||||
new OrdinalSales('2027', 55),
|
||||
new OrdinalSales('2028', 19),
|
||||
new OrdinalSales('2029', 66),
|
||||
new OrdinalSales('2030', 27),
|
||||
OrdinalSales('2014', 5),
|
||||
OrdinalSales('2015', 25),
|
||||
OrdinalSales('2016', 100),
|
||||
OrdinalSales('2017', 75),
|
||||
OrdinalSales('2018', 33),
|
||||
OrdinalSales('2019', 80),
|
||||
OrdinalSales('2020', 21),
|
||||
OrdinalSales('2021', 77),
|
||||
OrdinalSales('2022', 8),
|
||||
OrdinalSales('2023', 12),
|
||||
OrdinalSales('2024', 42),
|
||||
OrdinalSales('2025', 70),
|
||||
OrdinalSales('2026', 77),
|
||||
OrdinalSales('2027', 55),
|
||||
OrdinalSales('2028', 19),
|
||||
OrdinalSales('2029', 66),
|
||||
OrdinalSales('2030', 27),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
|
||||
Reference in New Issue
Block a user