Syncfusion Flutter Chart:条形图用对数 Y 轴反转 (< 1 Values)

问题描述 投票:0回答:1

我在 Syncfusion Flutter 图表中遇到倒转条的问题。当使用对数 y 轴且数据值均小于 1 时,条形图似乎向下而不是向上增长。这在视觉上具有误导性,并且不能准确代表我的数据。

这是我的代码片段:

class Values {
  final String x;
  final double y;

  Values(this.x, this.y);
}

List<Values> getChartData() {
  return [
       Values('CFI', 0.3),
    Values('CC', 0.1),
    Values('BLC', 0.03),
    Values('BDA', 0.01),
  ];
}

SfCartesianChart(
  title: ChartTitle(text: "Bar Graph"),
  primaryXAxis: const CategoryAxis(
    title: AxisTitle(
      text: 'Headers',
      textStyle: TextStyle(color: Color.fromARGB(255, 4, 20, 63)),
    ),
  ),
  primaryYAxis: const LogarithmicAxis(
    title: AxisTitle(
      text: 'Values',
      textStyle: TextStyle(color: Color.fromARGB(255, 4, 20, 63)),
    ),
  ),
  series: <CartesianSeries>[
    ColumnSeries<Values, String>(
      dataSource: getChartData(),
      xValueMapper: (Values course, _) => course.x,
      yValueMapper: (Values course, _) => course.y,
      dataLabelSettings: DataLabelSettings(isVisible: true),
      color: Color.fromARGB(255, 4, 20, 63),
      pointColorMapper: (Values data, _) => data.y < 20 ? Colors.red : Color.fromARGB(255, 4, 20, 63),
    ),
  ],
)

这是代码的输出: Inverted bar graphs

最初,我尝试在 Syncfusion Flutter 图表中设置对数轴的 isInverted 属性来反转条形。这成功地翻转了条形,但也翻转了 y 轴本身。现在,y 轴显示从最高到最低的值,这不是所需的行为。 isInverted =true

我注意到 y 轴上低于 1 的值是以倒转的方式绘制的。为了解决这个问题,我尝试将对数轴的最小值设置为图表中的最低数据点。然而,这并没有解决倒杠问题。 When logarithmic y axis is set to the lowest data point value

flutter dart bar-chart syncfusion yaxis
1个回答
0
投票

我想告诉你,1的对数是0,如果使用小于1的小数点数据,例如0.1或0.01,它们将导致对数轴上的负值。这是因为0.1的对数是-1,0.01的对数是-2。此行为是预期行为。

此外,我们已经使用具有对数轴的 Microsoft Excel 验证了此行为,并且当使用小于 1 的小数值时,Excel 生成的结果与我们图表中的结果类似。作为参考,我们附上了 Excel 中对数轴的输出。

Excel 对数轴输出:

© www.soinside.com 2019 - 2024. All rights reserved.