r-mzy47 / candlesticks

BSD 3-Clause "New" or "Revised" License
73 stars 74 forks source link

[Questions] Zoom and Reset #19

Closed The-Mr-L closed 2 years ago

The-Mr-L commented 2 years ago

hey again, so I noticed that zooming on windows the zoom in is scroll down and zoom out is scroll up is that intended? and I have more general quest about what is the best way to rest the state of the chart for when I select a new instrument for charting, I get index errors when I just override my chart state, I tried adding a unique key to the constructor of the widget . I realize this might be more a flutter question, I am new to flutter :) I am just doing a prototype of my project which has a vue3+ webview2 frontend for potential refactor

r-mzy47 commented 2 years ago

Hi. Yes, zooming on the chart using mouse scroll is intended. Do you have any problem with this? Could you please provide some code snippets so I can help you with that?

The-Mr-L commented 2 years ago

well it is just using the example of yours and it is the same result in the live demo. zooming works but it is reversed behavior to everything else zooming related mouse wheal up should zoom in etc :) and I cant seam to figure out a way to make the chart render on new data I mean new dataset like a a new stock etc

r-mzy47 commented 2 years ago

Try changing the key when you want to reset the chart. The unique key doesn't work because it passes the same key on every build. try building your key from your data. like: key: Key(SYMBOL + TIMEFRAME) so your chart resets every time TIMEFRAME or SYMBOL changes.

The-Mr-L commented 2 years ago

Yes that is what I have tried I am using Getx and I have made sure that the key is valid

uic is unique int id


class CandleChart extends GetView<MyController> {
  final List<Indicator> indicators = [
    BollingerBandsIndicator(
      length: 20,
      stdDev: 2,
      upperColor: const Color(0xFF2962FF),
      basisColor: const Color(0xFFFF6D00),
      lowerColor: const Color(0xFF2962FF),
    ),
    WeightedMovingAverageIndicator(
      length: 100,
      color: Colors.green.shade600,
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Obx(() =>
    Expanded(
      child: Row(
        children: [
           Text(controller.chart.value.uic.toString()),
          Candlesticks(
           key:Key(controller.chart.value.uic.toString()),
           candles: controller.getCandles4Chart(),
                  indicators: indicators,
                ),
        ],
      ),
    ),
    );
  }
}

and in my controller

List<candlesticks.Candle> getCandles4Chart() {
    return chart.value.daily.candles
        .map((c) => candlesticks.Candle(
            date: DateTime.fromMillisecondsSinceEpoch(
                (c.time.seconds * 1000).toInt()),
            high: c.high,
            low: c.low,
            open: c.open,
            close: c.close,
            volume: c.volume))
        .toList()
        .reversed
        .toList()
        ;
  }

this just results in the progress circle

r-mzy47 commented 2 years ago

Are you sure that the candles List is not empty?