我使用的是水平条形图,可以自动调整条形高度的大小。
https://google.github.io/charts/flutter/example/bar_charts/horizontal_bar_label.html
在本示例中,当我只有一个栏时,我想为该栏固定一个最大高度(例如10像素)。如何配置?
我在这里查看构造函数,但没有找到解决方案 https://pub.dev/documentation/charts_flutter/latest/flutter/BarChart-class.html
child: SizedBox(
width: 300.0,
height: 250.0,
child: charts.BarChart(
[
charts.Series<OrdinalSales, String>(
id: 'Sales',
domainFn: (OrdinalSales sales, _) => sales.year,
measureFn: (OrdinalSales sales, _) => sales.sales,
data: localData,
colorFn: (_, __) =>
charts.MaterialPalette.green.shadeDefault,
labelAccessorFn: (OrdinalSales sales, _) =>
'Category 1: ${sales.sales.toString()}')
],
animate: true,
vertical: false,
barRendererDecorator: new charts.BarLabelDecorator<String>(labelPosition: charts.BarLabelPosition.inside
),
domainAxis:
new charts.OrdinalAxisSpec(renderSpec: new charts.NoneRenderSpec()),
),
),
答案 0 :(得分:5)
根据以下说明,暂时无法执行此操作:https://github.com/google/charts/issues/167
但是我认为您可以通过创建其他具有透明颜色的项目或更改图表库代码来绕过此操作。
答案 1 :(得分:3)
您可以尝试将where gcc
包装到error: failed to run custom build command for \`backtrace-sys v0.1.37`
Caused by:
process didn't exit successfully: \`C:\Users\blahblah\AppData\Local\Temp\cargo-installEvEWRS\release\build\backtrace-sys-075604757ab74d2a\build-script-build` (exit code: 1)
--- stdout
cargo:rustc-cfg=rbt
TARGET = Some("x86_64-pc-windows-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "gcc.exe" "-O3" "-ffunction-sections" "-fdata-sections" "-m64" "-I" "src/libbacktrace" "-I" "C:\\Users\\BRENDA~1.BUR\\AppData\\Local\\Temp\\cargo-installEvEWRS\\release\\build\\backtra
ce-sys-1e77a4d4c3ba2eda\\out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=
1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrac
e_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktra
ce_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktr
ace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simpl
e=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-D
macho_get_view=__rbt_macho_get_view" "-Dmacho_symbol_type_relevant=__rbt_macho_symbol_type_relevant" "-Dmacho_get_commands=__rbt_macho_get_commands" "-Dmacho_try_dsym=__rbt_macho_try_dsym" "-Dm
acho_try_dwarf=__rbt_macho_try_dwarf" "-Dmacho_get_addr_range=__rbt_macho_get_addr_range" "-Dmacho_get_uuid=__rbt_macho_get_uuid" "-Dmacho_add=__rbt_macho_add" "-Dmacho_add_symtab=__rbt_macho_a
dd_symtab" "-Dmacho_file_to_host_u64=__rbt_macho_file_to_host_u64" "-Dmacho_file_to_host_u32=__rbt_macho_file_to_host_u32" "-Dmacho_file_to_host_u16=__rbt_macho_file_to_host_u16" "-o" "C:\\User
s\\BRENDA~1.BUR\\AppData\\Local\\Temp\\cargo-installEvEWRS\\release\\build\\backtrace-sys-1e77a4d4c3ba2eda\\out\\src/libbacktrace/alloc.o" "-c" "src/libbacktrace/alloc.c"
--- stderr
error occurred: Failed to find tool. Is `gcc.exe` installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)
中,并用BarChart
包装。
SizedBox
SingleChildScrollView
- SingleChildScrollView
- SizedBox
- charts.BarChart
的高度可以根据数据数来计算,例如:
SingleChildScrollView(
child: SizedBox(
height: 2000,
child: HorizontalBarLabelChart(
getData(),
),
),
),
对于100个元素
对于100个元素(因此高度为SizedBox
,因为numerOfElements * 50
)
答案 2 :(得分:0)
尝试执行此操作-
ConstrainedBox(
constraints: BoxConstraints.expand(height: 50.0), // adjust the height here
child: Your_chart_here, // place your chart here
),