cubejs_service 1.0.0 copy "cubejs_service: ^1.0.0" to clipboard
cubejs_service: ^1.0.0 copied to clipboard

A Dart package for interacting with Cube.js API and visualizing data using FL Chart.

example/cubejs_service_example.dart

import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:cubejs_service/cubejs_service.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late CubeJSService cubeService;
  List<FlSpot> chartData = [];

  @override
  void initState() {
    super.initState();
    cubeService = CubeJSService(
      cubeToken: 'your_cube_token',
      baseUrl: 'api.cubecloud.dev',
    );
    fetchData();
  }

  Future<void> fetchData() async {
    final query = {
      "measures": ["Orders.count"],
      "timeDimensions": [
        {
          "dimension": "Orders.createdAt",
          "dateRange": "Last 30 days"
        }
      ]
    };

    try {
      final rawData = await cubeService.fetchRawData(query);
      final flData = cubeService.convertToFlData(rawData, 'Orders.createdAt', 'Orders.count');
      setState(() {
        chartData = flData;
      });
    } catch (e) {
      print('Error fetching data: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('CubeJS with FL Chart')),
        body: Center(
          child: chartData.isNotEmpty
              ? LineChart(
                  LineChartData(
                    lineBarsData: [
                      LineChartBarData(
                        spots: chartData,
                        isCurved: true,
                        barWidth: 2,
                        colors: [Colors.blue],
                      ),
                    ],
                  ),
                )
              : CircularProgressIndicator(),
        ),
      ),
    );
  }
}
1
likes
130
points
31
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for interacting with Cube.js API and visualizing data using FL Chart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

fl_chart, flutter, http

More

Packages that depend on cubejs_service