Comments (3)
@marc-wilson Hey you can set handleBuiltInTouches
to false, which will not draw anything associated with touch events. Then you can build your custom functionality by listening to the events. Heres how I do it:
LineTouchData getLineTouchData() {
return LineTouchData(
touchTooltipData: LineTouchTooltipData(
tooltipBgColor: Colors.blueGrey.withOpacity(0.8),
tooltipMargin: 100,
),
touchCallback: (FlTouchEvent event, LineTouchResponse? response) {
if (response == null || response.lineBarSpots == null) {
return;
}
final index = response.lineBarSpots!.first.spotIndex;
if (event is FlPanStartEvent) {
ref.read(signalChartProvider.notifier).startDrag(index);
} else if (event is FlPanUpdateEvent) {
ref.read(signalChartProvider.notifier).updateDrag(index);
ref.read(signalChartProvider.notifier).toggleSpotSelectionDuringDrag(index);
} else if (event is FlPanEndEvent) {
ref.read(signalChartProvider.notifier).endDrag();
} else if (event is FlTapUpEvent) {
ref.read(signalChartProvider.notifier).toggleSpotSelection(index);
} else if (event is FlPointerHoverEvent) {
ref.read(signalChartProvider.notifier).updateHover(index);
} else if (event is FlPointerExitEvent) {
ref.read(signalChartProvider.notifier).updateHover(-1);
}
},
handleBuiltInTouches: false,
);
}
Then I would manually draw the vertical lines as ExtraLinesData:
ExtraLinesData getExtraLinesData(SignalChartState state) {
return ExtraLinesData(
extraLinesOnTop: true,
verticalLines: [
if (state.dragStartIndex != null)
VerticalLine(
x: state.dragStartIndex!.toDouble(),
color: Colors.black,
strokeWidth: 2,
),
if (state.hoverIndex != null)
VerticalLine(
x: state.hoverIndex!.toDouble(),
color: Colors.black,
strokeWidth: 2,
),
],
);
}
P.S Keep in mind I'm using riverbud for updating the widget, but you can use setState() instead if you don't :)
from fl_chart.
Co-pilot told me how to do it... not very intuitive, but it works. Is there a better solution than just making everything transparent in color to "hide" it?
getTouchedSpotIndicator: (barData, spotIndexes) {
return spotIndexes.map((spotIndex) {
final FlSpot spot = barData.spots[spotIndex];
if (spot.x == 0 || spot.x == barData.spots.length - 1)
return null;
return TouchedSpotIndicatorData(
const FlLine(
color: Colors.white,
strokeWidth: 1,
),
FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) {
return FlDotCirclePainter(
radius: 4,
color: Colors.transparent,
strokeWidth: 1,
strokeColor: Colors.transparent,
);
},
),
);
}).toList();
},
from fl_chart.
@translibrius's solution works
from fl_chart.
Related Issues (20)
- Draw a order around each sector HOT 1
- Exception: indicatorsData and touchedSpotOffsets size should be same. need help pls. HOT 2
- Ability to set different colors for parts of the line from a line chart HOT 1
- What is best way for make slider change y axis with fl_chart HOT 1
- Side titles are not placed the same way when values are translated
- How to customize LineTooltipItem
- NullSpot's isNull broken when using copyWith HOT 1
- Discrepancy in documentation
- Specify GraphArea height for barChart
- [Feature Request] Ability to replace LineTouchTooltipData widget HOT 5
- Programmatically display the tooltip for a given X value HOT 2
- I need to get offset extraLines of BarChart when touch it HOT 1
- How can I set the bottom title with the date and interval by time? HOT 2
- PieChart centerSpace disapearing HOT 3
- I can't find how to disable linechart's default animation. HOT 2
- Is the interval of SideTitles invalid for BarChart?
- Line Chart tooltip on only certain lines HOT 6
- Thorny LineChart HOT 5
- Is there a provision to change size of FlSpot? HOT 1
- TouchedSpotIndicator duplicates when updating chart
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fl_chart.