fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

Radar plot center point is zero

Open Athony1225 opened this issue 2 years ago • 16 comments

image I want the points with the value of zero to be concentrated on the center point as shown in the figure, but I don't know how to set it

Athony1225 avatar May 30 '23 09:05 Athony1225

Hello, I am also having the same question. Are we missing something here?

collamaf avatar May 30 '23 19:05 collamaf

Hello, I am also having the same question. Are we missing something here? I do not know, I searched, but could not find which property can be controlled. The screenshot below is the result of version 0.41.0, but this problem occurred after I updated to 0.62.0 image

Athony1225 avatar May 31 '23 01:05 Athony1225

I didn't understand your issue

imaNNeo avatar Jun 08 '23 14:06 imaNNeo

I didn't understand your issue

The 1 and 2 in the picture are the differences between the 0.62.0 and 0.41.0 versions, the 2 is the one I want. I don't know if there is a way to control this in version 0.62.0

image

Athony1225 avatar Jun 09 '23 03:06 Athony1225

I got the same problem too. I ran the sample file and modified the data like this image

And the result is as follows: image

I think the value 0 should be in the center of the radar, like the image below image

And an additional problem: when using other value combinations, the radar axis scales incorrectly. For example below: image image

mfatihz avatar Jul 17 '23 13:07 mfatihz

Same here... If you have any solution, just let me know please!

janosdupai avatar Aug 06 '23 13:08 janosdupai

Guys I "solved" the problem by superimposing my desired data with another dataset (made transparent so not actually shown) having both 0 and 100 as values Did I made it clean what I mean?

collamaf avatar Aug 06 '23 13:08 collamaf

I've encountered this problem too. May I ask when will the author fix it?

hardgit avatar Sep 19 '23 08:09 hardgit

Can someone please give me a reproducible code (a main.dart file) to let me fix the issue?

imaNNeo avatar Oct 01 '23 13:10 imaNNeo

You can use the example and replace rawDataSets in example/lib/presentation/samples/radar/radar_chart_sample1.dart as mentioned in my ticket with this simplified code:

List<RawDataSet> rawDataSets() {
    return [
      RawDataSet(
        title: 'Fashion',
        color: widget.fashionColor,
        values: [
          100,
          90,
          90,
        ],
      ),
    ];
}

ColinSchmale avatar Oct 06 '23 07:10 ColinSchmale

May I ask if there is any progress on this issue

git-boya avatar Jan 04 '24 13:01 git-boya

https://github.com/imaNNeo/fl_chart/issues/1078 broke the behaviour after version 0.6.2, i reverted to 0.6.1, and it works and to have the correct scale have a transparent dataset that contains max value and min value along with my actual dataset

 RadarDataSet(
       entryRadius: 8,
       fillColor: Colors.transparent,
       borderColor: Colors.transparent,
       borderWidth: 2,
      dataEntries:  [
         // Make sure the length of this dataset match the length of your original dataset.
         RadarEntry(value: 0), //minValue
         RadarEntry(value: 5) //maxValue
      ],
),

eldrig0 avatar Jan 15 '24 09:01 eldrig0

in radar_chart_painter.dart. if the dataSet has some data is zero, return default chart center.

  double getChartCenterValue(RadarChartData data) {
    final dataSetMaxValue = data.maxEntry.value;
    final dataSetMinValue = data.minEntry.value;

    // add this 
    if(dataSetMinValue == 0) return getDefaultChartCenterValue();

    final tickSpace = getSpaceBetweenTicks(data);
    final centerValue = dataSetMinValue - tickSpace;

    return dataSetMaxValue == dataSetMinValue
        ? getDefaultChartCenterValue()
        : centerValue;
  }

xiaao3 avatar Jun 05 '24 06:06 xiaao3

@imaNNeo This is the reproduction code.

Versions Flutter 3.19.6 Dart 3.3.4

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

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: RadarChart(
          RadarChartData(
            radarShape: RadarShape.polygon,
            tickCount: 3,
            dataSets: [
              RadarDataSet(
                dataEntries: [
                  RadarEntry(value: 0),
                  RadarEntry(value: 20),
                  RadarEntry(value: 100),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

simulator_screenshot_EA6E452B-CDB6-4D88-9855-7C27B705F84E

soraef avatar Jun 14 '24 05:06 soraef

I was able to find a temporary workaround to fix this issue by extending the RadarChartData class and overriding the minEntry getter to be equal to maxEntry (this forces the radar chart to set the center point to 0):

class RadarChartDataExtended extends RadarChartData {
  RadarChartDataExtended({
    List<RadarDataSet>? dataSets,
    RadarShape? radarShape,
    BorderSide? radarBorderData,
    double? titlePositionPercentageOffset,
    TextStyle? titleTextStyle,
    GetTitleByIndexFunction? getTitle,
    int? tickCount,
    BorderSide? tickBorderData,
    BorderSide? gridBorderData,
    TextStyle? ticksTextStyle,
  }) : super(
          dataSets: dataSets,
          radarShape: radarShape,
          radarBorderData: radarBorderData,
          titlePositionPercentageOffset: titlePositionPercentageOffset,
          titleTextStyle: titleTextStyle,
          getTitle: getTitle,
          tickCount: tickCount,
          tickBorderData: tickBorderData,
          gridBorderData: gridBorderData,
          ticksTextStyle: ticksTextStyle,
        );

  @override
  RadarEntry get minEntry => super.maxEntry;
}

And then using this class:

RadarChart(
    RadarChartDataExtended(
      dataSets: dataSets,
      radarShape: RadarShape.circle
      ...
    )
  );

tim-kodirov avatar Aug 02 '24 10:08 tim-kodirov

@tim-kodirov Thank you. It worked perfectly.

mafreud avatar Aug 07 '24 02:08 mafreud