![](/img/trans.png)
[英]charts_flutter - How to support non-zero Y-Axis values in bar chart with multiple stacks?
[英]charts_flutter: how to do a line chart overlapping y-axis label using Flutter Chart?
谁能帮我解决这个问题? 我正在使用charts_flutter 库,希望图表与y 轴label 重叠。
库: https://pub.dev/packages/charts_flutter
这是我的代码:
TimeSeriesChart(
seriesList,
dateTimeFactory: const LocalDateTimeFactory(),
animate: animate,
domainAxis: DateTimeAxisSpec(
renderSpec: GridlineRendererSpec(
labelStyle: new TextStyleSpec(
fontSize: MyDimens.chart_text_size, //
color: labelColor),
lineStyle: LineStyleSpec(
thickness: 0, color: MaterialPalette.transparent)),
),
primaryMeasureAxis: new NumericAxisSpec(
tickFormatterSpec: simpleCurrencyFormatter,
tickProviderSpec: new BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: MyDimens.chart_desired_tick_count,
),
renderSpec: new GridlineRendererSpec(
// Tick and Label styling here.
labelStyle: new TextStyleSpec(
fontSize: MyDimens.chart_text_size, //
color: labelColor),
// Change the line colors to match text color.
lineStyle: new LineStyleSpec(color: lineColor),
labelAnchor: TickLabelAnchor.after,
labelJustification: TickLabelJustification.inside,
)),
)
将zeroBound
参数设置为true
只需在 renderSpec 中为 labelOffsetFromAxisPx 设置一个负数,如下所示:
labelOffsetFromAxisPx = -15
要获得更好的结果,请将 labelJustification 更改为TickLabelJustification.outside
最后将您的代码更改为:
primaryMeasureAxis: new NumericAxisSpec(
tickFormatterSpec: simpleCurrencyFormatter,
tickProviderSpec: new BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: MyDimens.chart_desired_tick_count,
),
renderSpec: new GridlineRendererSpec(
// Tick and Label styling here.
labelStyle: new TextStyleSpec(
fontSize: MyDimens.chart_text_size, //
color: labelColor),
// Change the line colors to match text color.
lineStyle: new LineStyleSpec(color: lineColor),
labelAnchor: TickLabelAnchor.after,
labelJustification: TickLabelJustification.outside,
// Add offset herer
labelOffsetFromAxisPx: -15,
)),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.