I'm using charts_flutter and using a scrollable bar chart. Horizontal scrolling works great with the behaviors SlidingViewport() and PanAndZoomBehavior() (charts_flutter example). I would also like to have labels follow the bar itself and stay inside the chart window when scrolling. See image.
Code
BarChart(
data,
behaviors: [
SlidingViewport(),
PanAndZoomBehavior(),
],
animate: true,
domainAxis: OrdinalAxisSpec(
viewport: OrdinalViewport('Week ${weeks.last}', 4),
),
)
I used ClipRect() to solve that issue, simply wrap your widget with what ever clipper you wish although the default works as well,
ClipRect(child : BarChart(
data,
behaviors: [
SlidingViewport(),
PanAndZoomBehavior(),
],
animate: true,
domainAxis: OrdinalAxisSpec(
viewport: OrdinalViewport('Week ${weeks.last}', 4),
),
))
Related
I used the flutter_colorpicker package to implement a color picker in my app. My widget looks something like this:
ColorPicker(
pickerColor: ...,
paletteType: PaletteType.hueWheel,
onColorChanged: (color) {
...
},
enableAlpha: false,
labelTypes: const [],
)
In the UI it looks like this:
Now I want to remove the brightness bar on the bottom. I know that the color picker is not complete without that brighness bar but I will handle the brightness a different way. I have found no official documentation on how to achieve this.
How do I remove that bar? Hacks are also welcome or somehow extending the package with inheritance.
Here I attach some links which contains no brightnesss bar
Flutter Material Color Picker
Flex Color Picker
I have solved the problem by clipping away that bar using a ClipRect widget:
ClipRect(
child: Align(
alignment: Alignment.topCenter,
heightFactor: 0.75,
child: ColorPicker(
...
colorPickerWidth: 250,
),
),
);
I have not found any unwanted side effects with this approach yet.
I want to rotate the bar chart label decorators 90 degrees.
In my flutter app I draw a simple vertical bar chart of daily amounts (using charts_flutter 0.10.0) with labels on both a numeric y-axis and ordinal x-axis.
These axis labels can be styled and easily rotated using labelRotation. The vertical bars also each have 'bar label decorator' labels that show the exact graphed amount – but because of size constraints and resulting narrow bars, the label decorators overflow.
I need to rotate these bar decorator labels 90 degrees, so they run in the same direction as each bar's long axis, allowing the label text to fit – but cannot work out how.
Unlike for the axis labels of primaryMeasureAxis and domainAxis, which have a labelRotation property in their renderSpec, the bar label decorators don't seem to have any option other than simple text styling (fontFamily, fontSize, lineHeight, color, fontWeight) or label position behaviour via BarLabelDecorator.
My guess is that this isn't currently possible without an update to BarLabelDecorator to provide a rotate option. I am hoping I'm wrong!
Widget build(BuildContext context) {
charts.NumericAxisSpec yAxisStyling = charts.NumericAxisSpec(
renderSpec: charts.GridlineRendererSpec(
labelStyle: charts.TextStyleSpec(
fontSize: 12,
color: charts.ColorUtil.fromDartColor(Colors.grey.shade500),
),
lineStyle: new charts.LineStyleSpec(
color: charts.ColorUtil.fromDartColor(Colors.grey.shade400)),
)
);
charts.OrdinalAxisSpec xAxisStyling = charts.OrdinalAxisSpec(
renderSpec: charts.GridlineRendererSpec(
labelStyle: charts.TextStyleSpec(
fontSize: 12,
color: charts.ColorUtil.fromDartColor(Colors.grey.shade500),
),
// labelRotation: 90, // <- just an example / don't need these rotated
lineStyle: new charts.LineStyleSpec(color: charts.MaterialPalette.transparent),
),
showAxisLine: false, // doesn't seem to work on it's own - need above 'transparent' line
);
return new charts.BarChart(
seriesList,
animate: animate,
vertical: true,
// Set a bar label decorator.
// insideLabelStyleSpec: new charts.TextStyleSpec(),
// outsideLabelStyleSpec: new charts.TextStyleSpec(...)),
barRendererDecorator: new charts.BarLabelDecorator<String>(), // <- ? no rotate property
primaryMeasureAxis: yAxisStyling,
domainAxis: xAxisStyling,
);
}
In case anyone else is looking...
Although there is (currently) no way to achieve this natively with the public release of the google charts flutter package, this answer to "Is there a way to put label text vertically in flutter charts_flutter: ^0.8.1" describes a workaround through custom extension of the BarRendererDecorator class.
The money-line is by ultimately rotating the direction of drawing text on the canvas:
canvas.drawText(labelElement, labelX, labelY, rotation: -math.pi / 2);
The complete solution is probably not the most maintainable (in terms of becoming technical debt as the charts package is inevitably updated), but it will do the job.
(In the mean-time I've decided against decorating the bars, and instead use a tap gesture to show custom tooltips on the bar value etc. Neater and less crowding of the UI, especially on small screens.)
I'm using google charts for flutter and trying to align legends in the bottom middle.
I've tried using outsideJustification: charts.OutsideJustification.middleDrawArea but its still aligned left. Is there an option to align legends in the center?
this is what i have
charts.NumericComboChart(
data,
animate: true,
// hide Axis
primaryMeasureAxis: noneAxisRenderer,
// hide Axis
secondaryMeasureAxis: noneAxisRenderer,
// hide Axis
domainAxis: noneAxisRenderer,
// Configure the default renderer as a line renderer. This will be used
// for any series that does not define a rendererIdKey.
defaultRenderer: charts.LineRendererConfig(),
// Custom renderer configuration for the point series.
behaviors: [
charts.SeriesLegend(
position: charts.BehaviorPosition.bottom,
cellPadding: EdgeInsets.symmetric(horizontal: 2.0),
outsideJustification: charts.OutsideJustification.middleDrawArea,
),
],
);
which results in this:
I used https://github.com/google/charts inside my flutter app. It works great. But when i zoom on chart, the zoom happens but in the wrong place! It starts expanding keeping the left static. The effect is the chart slide under your finger zooming not in the point you are zooming to. Is there a way to zoom like you zoom on a picture on gallery?
code of my chart
Widget build(BuildContext context) {
return new charts.LineChart(
_chartSeriesFromChartData(seriesList),
animate: false,
defaultRenderer: charts.LineRendererConfig(includeArea: true, includePoints: true),
primaryMeasureAxis: charts.NumericAxisSpec(tickProviderSpec: charts.BasicNumericTickProviderSpec(desiredTickCount: 8)),
behaviors: [ZoomBehaviour()],
)
You can use code like this in your code:
behaviors: [new charts.PanAndZoomBehavior()],
or if you want selection by item in our charts you can use:
behaviors: [new charts.SeriesLegend()],
and if you want use two of them maybe you can use:
behaviors: [new charts.SeriesLegend(), new charts.PanAndZoomBehavior()],
I implemented SlideTransition for a widget in flutter, and it slides in as expected. The issue is that before the animation is called, the space where the slider is going to be displayed later is empty.
How can I make the parent to give this space to other widgets in the layout until the moment that a slider comes into view?
I was thinking about giving a slider the initial height of zero, but then the widgets inside the slider would act funny as the height changes in sync with sliding. I wonder if there is a simpler way.
The parent is:
new Scaffold(
appBar: _appBar,
body: new Column(
children: <Widget>[
new Expanded(
child: _body;
}),
),
new SlideTransition(
position: _sliderPosition, //
child: _slider,
),
],
);
And the position is defined as:
_sliderPosition = new MaterialPointArcTween(
begin: const Offset(0.0, 1.0),
end: Offset.zero,
).animate(_animationController);
I solved this issue by replacing _slider with _buildSlider() which returns null until a slider is needed.
This is also better for performance as there is no need to render a slider if it's hidden.
Bumped into the same issue with a SlideTransition taking the full height during a vertical slide. In the end I achieved the slide effect by using a SizeTransition instead, and setting its axisAlignment property accordingly (-1, 0, 1 for top/center/bottom in my case).