mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 06:18:49 +00:00
web/chart: fix sample (#909)
This commit is contained in:
@@ -25,11 +25,12 @@ class CustomAxisTickFormatters extends StatelessWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
CustomAxisTickFormatters(this.seriesList, {this.animate});
|
||||
const CustomAxisTickFormatters(this.seriesList, {this.animate, Key key})
|
||||
: super(key: key);
|
||||
|
||||
/// Creates a [TimeSeriesChart] with sample data and no transition.
|
||||
factory CustomAxisTickFormatters.withSampleData() {
|
||||
return new CustomAxisTickFormatters(
|
||||
return CustomAxisTickFormatters(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -41,29 +42,29 @@ class CustomAxisTickFormatters extends StatelessWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory CustomAxisTickFormatters.withRandomData() {
|
||||
return new CustomAxisTickFormatters(_createRandomData());
|
||||
return CustomAxisTickFormatters(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<MyRow, DateTime>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new MyRow(new DateTime(2017, 9, 25), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 9, 26), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 9, 27), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 9, 28), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 9, 29), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 9, 30), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 10, 01), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 10, 02), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 10, 03), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 10, 04), random.nextInt(100)),
|
||||
new MyRow(new DateTime(2017, 10, 05), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 9, 25), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 9, 26), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 9, 27), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 9, 28), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 9, 29), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 9, 30), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 10, 01), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 10, 02), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 10, 03), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 10, 04), random.nextInt(100)),
|
||||
MyRow(DateTime(2017, 10, 05), random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<MyRow, DateTime>(
|
||||
charts.Series<MyRow, DateTime>(
|
||||
id: 'Cost',
|
||||
domainFn: (MyRow row, _) => row.timeStamp,
|
||||
measureFn: (MyRow row, _) => row.cost,
|
||||
@@ -79,8 +80,8 @@ class CustomAxisTickFormatters extends StatelessWidget {
|
||||
///
|
||||
/// This is what is used in the [NumericAxisSpec] below.
|
||||
final simpleCurrencyFormatter =
|
||||
new charts.BasicNumericTickFormatterSpec.fromNumberFormat(
|
||||
new NumberFormat.compactSimpleCurrency());
|
||||
charts.BasicNumericTickFormatterSpec.fromNumberFormat(
|
||||
NumberFormat.compactSimpleCurrency());
|
||||
|
||||
/// Formatter for numeric ticks that uses the callback provided.
|
||||
///
|
||||
@@ -91,11 +92,11 @@ class CustomAxisTickFormatters extends StatelessWidget {
|
||||
// final customTickFormatter =
|
||||
// charts.BasicNumericTickFormatterSpec((num value) => 'MyValue: $value');
|
||||
|
||||
return new charts.TimeSeriesChart(seriesList,
|
||||
return charts.TimeSeriesChart(seriesList,
|
||||
animate: animate,
|
||||
// Sets up a currency formatter for the measure axis.
|
||||
primaryMeasureAxis: new charts.NumericAxisSpec(
|
||||
tickFormatterSpec: simpleCurrencyFormatter),
|
||||
primaryMeasureAxis:
|
||||
charts.NumericAxisSpec(tickFormatterSpec: simpleCurrencyFormatter),
|
||||
|
||||
/// Customizes the date tick formatter. It will print the day of month
|
||||
/// as the default format, but include the month and year if it
|
||||
@@ -103,30 +104,30 @@ class CustomAxisTickFormatters extends StatelessWidget {
|
||||
///
|
||||
/// minute, hour, day, month, and year are all provided by default and
|
||||
/// you can override them following this pattern.
|
||||
domainAxis: new charts.DateTimeAxisSpec(
|
||||
tickFormatterSpec: new charts.AutoDateTimeTickFormatterSpec(
|
||||
day: new charts.TimeFormatterSpec(
|
||||
domainAxis: const charts.DateTimeAxisSpec(
|
||||
tickFormatterSpec: charts.AutoDateTimeTickFormatterSpec(
|
||||
day: charts.TimeFormatterSpec(
|
||||
format: 'd', transitionFormat: 'MM/dd/yyyy'))));
|
||||
}
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<MyRow, DateTime>> _createSampleData() {
|
||||
final data = [
|
||||
new MyRow(new DateTime(2017, 9, 25), 6),
|
||||
new MyRow(new DateTime(2017, 9, 26), 8),
|
||||
new MyRow(new DateTime(2017, 9, 27), 6),
|
||||
new MyRow(new DateTime(2017, 9, 28), 9),
|
||||
new MyRow(new DateTime(2017, 9, 29), 11),
|
||||
new MyRow(new DateTime(2017, 9, 30), 15),
|
||||
new MyRow(new DateTime(2017, 10, 01), 25),
|
||||
new MyRow(new DateTime(2017, 10, 02), 33),
|
||||
new MyRow(new DateTime(2017, 10, 03), 27),
|
||||
new MyRow(new DateTime(2017, 10, 04), 31),
|
||||
new MyRow(new DateTime(2017, 10, 05), 23),
|
||||
MyRow(DateTime(2017, 9, 25), 6),
|
||||
MyRow(DateTime(2017, 9, 26), 8),
|
||||
MyRow(DateTime(2017, 9, 27), 6),
|
||||
MyRow(DateTime(2017, 9, 28), 9),
|
||||
MyRow(DateTime(2017, 9, 29), 11),
|
||||
MyRow(DateTime(2017, 9, 30), 15),
|
||||
MyRow(DateTime(2017, 10, 01), 25),
|
||||
MyRow(DateTime(2017, 10, 02), 33),
|
||||
MyRow(DateTime(2017, 10, 03), 27),
|
||||
MyRow(DateTime(2017, 10, 04), 31),
|
||||
MyRow(DateTime(2017, 10, 05), 23),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<MyRow, DateTime>(
|
||||
charts.Series<MyRow, DateTime>(
|
||||
id: 'Cost',
|
||||
domainFn: (MyRow row, _) => row.timeStamp,
|
||||
measureFn: (MyRow row, _) => row.cost,
|
||||
|
||||
Reference in New Issue
Block a user