Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

Flutter Charts - marker color not matching series color

I am using TimeSeriesChart from the flutter_charts package, and the colors of the selected markers are not matching up with their corresponding line color. There is also no data from other series hiding behind these data points.

enter image description here

Since the series is dynamic, I am setting to colorFn using math.Random to generate random colors for each series.

Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0))

I'm not sure how this would affect the markers, though, since the series is compiled before the markers are used. Here is the function I'm using to build my series, along with the chart

List<charts.Series<ResultSummary, DateTime>> _createChartData() {
    // create chart map
    Map<String, List<ResultSummary>> chartMap = {};
    ConsumerTargetResults selectedTargetResults = getConsumerTargetResults(resultsPool, [selectedTarget])[0];
    Map<String, Color> promptColorMap = {};
    promptColorMap['Independent'] = Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
    promptColorMap.addAll(Map.fromIterable(selectedTargetResults.target.prompts, key: (p) =>
      p.title, value: (p) => Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0))
    );
    promptColorMap.forEach((key, value) {
      List<ResultSummary> resultSummaries = [];
      for (Session s in selectedTargetResults.sessions) {
        ResultSummary tResultSummary = ResultSummary(s.date, 0, value);
        if (s.promptStatsMap[key] != null) tResultSummary.measure = s.promptStatsMap[key];
        resultSummaries.add(tResultSummary);
      }
      chartMap[key] = resultSummaries;
    });

    // implement to chart
    List<charts.Series<ResultSummary, DateTime>> chartDataList = [];
    chartMap.forEach((key, value) {
      chartDataList.add(
        charts.Series<ResultSummary, DateTime>(
        id: key,
        data: value,
        domainFn: (ResultSummary r, _) => r.domain,
        measureFn: (ResultSummary r, _) => r.measure,
        fillColorFn: (ResultSummary r, _) => r.color,
      ));
    });
    return chartDataList;
  }

    Expanded(
      child: Container(
          padding: EdgeInsets.fromLTRB(40.0, 10.0, 40.0, 10.0),
          child: charts.TimeSeriesChart(
            widget.seriesList,
            // animate: widget.animate,
            animate: false,
            behaviors: [ charts.SeriesLegend(
              position: charts.BehaviorPosition.end,
              outsideJustification: charts.OutsideJustification.endDrawArea,
              horizontalFirst: false,
              desiredMaxColumns: 1,
              cellPadding: EdgeInsets.only(right: 4.0, bottom: 4.0),
              entryTextStyle: charts.TextStyleSpec(
                  color: charts.MaterialPalette.purple.shadeDefault,
                  fontFamily: 'Georgia',
                  fontSize: 11),
            )],
            selectionModels: [
              charts.SelectionModelConfig(
                type: charts.SelectionModelType.info,
                changedListener: _onSelectionChanged,
                updatedListener: _onSelectionChanged,
              )
            ],
          )),
    ),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I removed the colorFn field from my chart and that seemed to have done the trick

enter image description here

// implement to chart series
List<charts.Series<ResultSummary, DateTime>> chartDataList = [];
chartMap.forEach((key, value) {
  chartDataList.add(
    charts.Series<ResultSummary, DateTime>(
    id: key,
    data: value,
    domainFn: (ResultSummary r, _) => r.domain,
    measureFn: (ResultSummary r, _) => r.measure,
    // fillColorFn: (ResultSummary r, _) => r.color,
  ));
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...