Coder Social home page Coder Social logo

Comments (7)

entronad avatar entronad commented on May 14, 2024

It should.
Can you please provide your example code to let me check the problem.

from graphic.

SSebigo avatar SSebigo commented on May 14, 2024
return Observer(builder: (_) {
  if (context.watch<ResultatsStore>().answersChart.isEmpty) {
    return Center(
      child: Text(
        'Aucune donnée disponible',
        style: Theme.of(context).textTheme.headline6,
      ),
    );
  }
  return Chart(
    data: context.watch<ResultatsStore>().answersChart,
    variables: {
      'Note': Variable(
        accessor: (Map map) => map['Note'] as String,
      ),
      'Réponses': Variable(
        accessor: (Map map) => map['Réponses'] as num,
      ),
      'index': Variable(
        accessor: (Map map) => map['index'] as num,
      ),
    },
    elements: [
      IntervalElement(
        color: ColorAttr(
          variable: 'index',
          values: [
            Palette.rose,
            Palette.green,
            Palette.grey,
          ],
        ),
        size: SizeAttr(
          value: (mediaQuery.width /
                  context.watch<ResultatsStore>().answersChart.length) *
              0.5,
        ),
      ),
    ],
    axes: [
      Defaults.horizontalAxis,
      Defaults.verticalAxis,
    ],
    selections: {
      'tap': PointSelection(
        on: {
          GestureType.hover,
          GestureType.tap,
        },
        dim: 1,
      )
    },
    tooltip: TooltipGuide(
      backgroundColor: Palette.black,
      elevation: 5,
      textStyle: TextStyles.caption.copyWith(color: Palette.white),
      variables: ['Note', 'Réponses'],
    ),
    crosshair: CrosshairGuide(),
  );
});

Note here that answersChart is a List<Map<String, dynamic>> modified inside ResultatsStore calling this method:

@action
void calculateAnswersChart() {
  answersChart.clear();

  log.fine('calculateAnswersChart | rs.copyMap: ${copyMap.length}');
  for (final entry in copyMap.entries) {
    final copy = entry.value;
    final notes = copy.notes[critere?.idDef];
    final notesStr = (critere as Question)
        .propositions
        .map((e) => String.fromCharCode(96 + e.numero).toUpperCase())
        .toSet()
        .toList();
    String note = '';

    // fill with all default notes
    for (final noteStr in notesStr) {
      answersChart.add(ObservableMap<String, dynamic>.of(<String, dynamic>{
        'index': 0,
        'Note': noteStr,
        'Réponses': 0,
      }));
    }
etc...

PS: somehow I can't click on the graph bars

from graphic.

SSebigo avatar SSebigo commented on May 14, 2024

Also, even if I remove the Observer it still ends with the same result, the chart goes blank when data are updated.

The only way to have the updated chart is to switch to a different view and then come back to the chart.
I suppose it redraws when views are switched).

from graphic.

entronad avatar entronad commented on May 14, 2024

The data updating problem is caused by a bug in the _ChartLayoutDelegate.
I have fixed it in the v0.6.1, please have a try. (It requires a Flutter version greater than 2.6.0, there is a breaking change in the gesture lib).

The click problem dosen't show in my test, I copied your selections and tooltip setting.

from graphic.

SSebigo avatar SSebigo commented on May 14, 2024

Oh one last problem, seems like in a bar chart, say there are 2 labels and each one have a value of 1, no bar is displayed

Example, if this is my data:
[{index: 0, label: 0, value: 1, color: Color(0xffb64384)}, {index: 1, label: 1, value: 1, color: Color(0xfff8bf2f)}]
then the chart is empty (the labels are displayed but there is no bar).

from graphic.

entronad avatar entronad commented on May 14, 2024

If the label position is right, the problem may caused by color or size attribute.

from graphic.

SSebigo avatar SSebigo commented on May 14, 2024

I'll take a look, thanks. I close the issue since the original one is patched (works like a charm).

from graphic.

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.