Code Monkey home page Code Monkey logo

Comments (2)

PreethikaSelvam avatar PreethikaSelvam commented on July 17, 2024

Hi @bilalep,

We have analyzed your query and found that the reported issue occurs only when we use the bloc to convert a stream, replacing the first data points with the new data. This issue is scheduled to be fixed in our upcoming weekly release which is scheduled on June 25, 2024. We will update you here once the release is rolled out and we appreciate your patience until then.

Additionally, if your requirement is to add new data to the end of the pervious data using bloc to convert a stream, we suggest the below code snippets and sample to achieve your requirement.

Code Snippet:

`
late CandleBloc _bloc;

List _chartData = [];

@OverRide

void initState() {

super.initState();

_bloc = CandleBloc();

_bloc.candleStream.listen((data) {

  setState(() {

    _chartData.addAll(data);

  });

});

}

@OverRide

void dispose() {

_bloc.dispose();

super.dispose();

}

@OverRide

Widget build(BuildContext context) {

return Scaffold(

  appBar: AppBar(

    title: Text('Candle Chart Demo'),

  ),

  body: Center(

    child: _chartData.isNotEmpty

        ? Padding(

            padding: const EdgeInsets.all(8.0),

            child: SizedBox(

              height: 300,

              child: SfCartesianChart(

                primaryXAxis: DateTimeAxis(),

                primaryYAxis: NumericAxis(),

                series: _getCandleSeries(_chartData),

              ),

            ),

          )

        : CircularProgressIndicator(),

  ),

);

}

List<CandleSeries<CandleChartData, DateTime>> _getCandleSeries(

  List<CandleChartData> data) {

return <CandleSeries<CandleChartData, DateTime>>[

  CandleSeries<CandleChartData, DateTime>(

    dataSource: data,

    xValueMapper: (CandleChartData sales, _) => sales.timestamp,

    lowValueMapper: (CandleChartData sales, _) => sales.low,

    highValueMapper: (CandleChartData sales, _) => sales.high,

    openValueMapper: (CandleChartData sales, _) => sales.open,

    closeValueMapper: (CandleChartData sales, _) => sales.close,

  ),

];

}

}

class CandleBloc {

final _candleController = StreamController<List>.broadcast();

Stream<List> get candleStream => _candleController.stream;

CandleBloc() {

_startGeneratingData();

}

void _startGeneratingData() {

Timer.periodic(Duration(seconds: 1), (timer) {

  final candle = CandleChartData(

    open: 20 + Random().nextInt(10).toDouble(),

    close: 20 + Random().nextInt(10).toDouble(),

    high: 20 + Random().nextInt(10).toDouble(),

    low: 20 + Random().nextInt(10).toDouble(),

    timestamp: DateTime.now(),

  );

  _addCandle(candle);

});

}

void _addCandle(CandleChartData candle) {

_candleController.sink.add([candle]);

}

void dispose() {

_candleController.close();

}

}

`

Please let us know if you need any further assistance.

Regards,

Preethika Selvam.
gh1916.zip

from flutter-widgets.

PreethikaSelvam avatar PreethikaSelvam commented on July 17, 2024

Hi @bilalep,

We have fixed the range exception that occurs when using the bloc to convert a stream for replacing the first data points with the new data points. This fix has been included in the latest version below. Therefore, we kindly request that you upgrade the syncfusion_flutter_charts package to the latest version below to avoid this issue.

Version: https://pub.dev/packages/syncfusion_flutter_charts/versions/26.1.39

Root cause: Missed to consider the candle line rendering when the candle series, open and close values are the same.

Regards,

Preethika Selvam.

from flutter-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.