Flutter 如何在颤振图中应用线性梯度?
如何在颤振图中应用线性梯度 我尝试过颜色类,但我只能应用纯色,无法找到在图形栏中使用渐变的方法Flutter 如何在颤振图中应用线性梯度?,flutter,colors,gradient,Flutter,Colors,Gradient,如何在颤振图中应用线性梯度 我尝试过颜色类,但我只能应用纯色,无法找到在图形栏中使用渐变的方法 chart.Series<Person,String>( id:"Person3", colorFn:(_,__)=>chart.MaterialPalette.red.shadeDefault, domainFn: (Person dataPoint, _)=>dataPoint.name, measureFn: (Person dataPoi
chart.Series<Person,String>(
id:"Person3",
colorFn:(_,__)=>chart.MaterialPalette.red.shadeDefault,
domainFn: (Person dataPoint, _)=>dataPoint.name,
measureFn: (Person dataPoint, _)=>dataPoint.no,
data:data2,
)
chart.Series(
id:“个人3”,
颜色fn:(u,uu)=>chart.materialpalete.red.shadedFault,
domainFn:(Person dataPoint,)=>dataPoint.name,
measureFn:(个人数据点,)=>dataPoint.no,
数据:数据2,
)
提供一些方法来应用线性渐变使用
Container
的属性BoxDecoration
可以实现它,如下所示:
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: 370,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors(0XFFA573FF),
blurRadius: 10,
offset: Offset(2, 3)),
],
borderRadius: BorderRadius.all(Radius.circular(18)),
gradient: LinearGradient(colors: [
color: Colors(0XFFA573FF),
color: Colors(0XFF645AFF),
], stops: [
0.35,
1
], begin: Alignment.topLeft, end: Alignment.bottomRight)),
child:
SizedBox(
height: 280,
width: double.infinity,
child: StackedAreaCustomColorLineChart(
StackedAreaCustomColorLineChart._createSampleData())
// replace child with your chart here
),
);
}
面积序列图示例
@override
Widget build(BuildContext context) {
final List<Color> color = <Color>[];
color.add(Colors.blue[50]);
color.add(Colors.blue[100]);
color.add(Colors.blue);
final List<double> stops = <double>[];
stops.add(0.0);
stops.add(0.5);
stops.add(1.0);
final LinearGradient gradientColors =
LinearGradient(colors: color, stops: stops);
return Container(
width: double.infinity,
height: 250,
child: SfCartesianChart(
primaryXAxis: CategoryAxis(),
series: <AreaSeries<SalesData, String>>[
AreaSeries<SalesData, String>(
dataSource: <SalesData>[
SalesData('Jan', 85),
SalesData('Feb', 58),
SalesData('Mar', 64),
SalesData('Apr', 62),
SalesData('May', 78),
SalesData('Jun', 92),
SalesData('Jul', 90),
],
xValueMapper: (SalesData sales, _) => sales.year,
yValueMapper: (SalesData sales, _) => sales.sales,
gradient: gradientColors,
),
],
),
);
}
@覆盖
小部件构建(构建上下文){
最终列表颜色=[];
添加(Colors.blue[50]);
添加(Colors.blue[100]);
颜色。添加(颜色。蓝色);
最终列表停止=[];
停止。添加(0.0);
停止。添加(0.5);
停止。添加(1.0);
最终线性梯度颜色=
LinearGradient(颜色:颜色,停止:停止);
返回容器(
宽度:double.infinity,
身高:250,
儿童:SfCartesianChart(
primaryXAxis:CategoryAxis(),
系列:[
面积系列(
数据源:[
SalesData(1985年1月),
SalesData(58年2月),
SalesData('64年3月),
SalesData(62年4月),
SalesData(78年5月),
SalesData(1992年6月),
SalesData(1990年7月),
],
xValueMapper:(SalesData sales,)=>sales.year,
yValueMapper:(SalesData sales,)=>sales.sales,
渐变:渐变颜色,
),
],
),
);
}
显然还没有这样的功能。我成功地使用以下代码使其工作:
Widget\u buildChart(){
返回容器(
身高:300,
孩子:沙德尔马斯克(
孩子:图表。条形图(
_createRandomData(),
动画:对,
primaryMeasureAxis:新图表。数值轴规范(
renderSpec:new charts.NoneRenderSpec(),showAxisLine:false),
domainAxis:新图表(
showAxisLine:false,renderSpec:new charts.NoneRenderSpec()),
layoutConfig:new charts.layoutConfig(
leftMarginSpec:新图表。MarginSpec。fixedPixel(0),
topMarginSpec:新图表。MarginSpec。固定像素(0),
rightMarginSpec:新图表。MarginSpec。固定像素(0),
bottomMarginSpec:新图表。MarginSpec.fixedPixel(0)),
defaultRenderer:new charts.dererConfig(
cornerStrategy:const图表。ConstCornerStrategy(30)),
),
着色器回调:(矩形边界){
返回线半径(
开始:对齐.bottomCenter,
结束:对齐。上止点,
颜色:[颜色(0xFF51DE93)、颜色(0xFFFFB540)、颜色(0xFFFA4169)],
停止:[
0.0,
0.5,
1.0,
],
).createShader(边界);
},
blendMode:blendMode.srcATop,
)
);
}
结果:
我要求提供图表。这一个适用于普通的小部件,而不是图表库。谢谢你的回答。但我有一个问题是如何减少高度,因为当我使用你的代码时,大小不是减少的,它占据了整个页面的高度