question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AreaChart + tooltip

See original GitHub issue

What is the problem?

I can’t make onPress working on AreaChart, I would like to show a popup with additional information when pressed (Ideally i would like to be onMove but I don’t see the possibility in the library)

What platform?

Running natively on the ios simulator, no expo

  • [latest on xr] iOS
  • Android

React Native version: 0.57.6

Code to reproduce

Please notice all onPress are commented out but neither was working

  render () {
    const points = [1,4,21,3,7,100, 50, 20, 1,3,5,6,76,33,46,88]

    const Gradient = () => (
      <Defs key={'gradient'}>
        <LinearGradient id={'gradient'} x1={'0'} y={'100%'} x2={'0'} y2={'50%'}>
          <Stop offset={'0%'} stopColor={'rgb(64, 135, 249)'} stopOpacity={0.1}/>
          <Stop offset={'100%'} stopColor={'rgb(64, 135, 249)'} stopOpacity={0.05}/>
        </LinearGradient>
      </Defs>
    )

    const indexToClipFrom = 10

    const Line = ({ line }) => (
      <Path
        key={'line'}
        d={line}
        stroke={'rgb(28, 114, 147)'}
        fill={'none'}
        // onPress={(a, b, c) => console.tron.log(a, b, c)}
      />
    )

    return (
      <AreaChart
        style={{ height: 200, width: Dimensions.get('window').width }}
        data={points}
        contentInset={{ top: 20, bottom: 20 }}
        // onPress={(a,b,c) => console.tron.log(a,b,c)}
        svg={{
          fill: 'url(#gradient)',
          // onPress: (a, b, c) => console.tron.log(a, b, c)
        }}
      >
        <Gradient />
        <Line />
        {/* <Tooltip /> */}
      </AreaChart>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
vrinchcommented, Mar 25, 2020

@AravindTReddy

I was able to achieve onPress and not onMove

` import React from ‘react’ import { View, Alert } from ‘react-native’ import { BarChart, Grid } from ‘react-native-svg-charts’ import { Text, Line, Circle, G, Rect, } from ‘react-native-svg’

          const data = [ 10, 5, 25, 15, 20 ]

          class App extends React.PureComponent {

            constructor(props) {
              super(props);
              this.state = {
                selected: {},
              }
            }

            handlePress({ value, index }) {
              const selected = {
                index,
                value
              };
              this.setState({ selected, })
              //Alert.alert(index, value);
            }
              render() {
                const { selected } = this.state;

                    const Labels = ({ x, y, bandwidth, data }) => (
                        <G
                          key={ selected.index }
                          x={ x(selected.index) }
                          y={y(selected.value) - 80 }
                          onPress={ () => alert('tooltip clicked') }
                        >
                          <Rect
                            height={ 30 }
                            width={ 60 }
                            stroke={ 'grey' }
                            fill={ 'white' }
                            ry={ 10 }
                            rx={ 10 }
                          />
                          <Text
                            x={ 60 / 2 }
                            dy={ 16 }
                            alignmentBaseline={ 'middle' }
                            textAnchor={ 'middle' }
                            stroke={ 'rgb(134, 65, 244)' }
                          >
                            { `${selected.value}ºC` }
                          </Text>
                        <G
                          x={ 60 / 2 }
                        >
                          <Line
                          y1={ 60 / 2 }
                          y2={ y(31) }
                          stroke={ 'grey' }
                          strokeWidth={ 2 }
                        />
                        </G>
                      </G>
                  )


                          const pieData = data
                      .map((value, index) => ({
                          value,
                          svg: {
                              fill: selected.value === value ? 'orange' : 'blue',
                              onPress: this.handlePress.bind(this, { index, value }),
                          },
                          key: `pie-${index}`,
                      }))


                  return (
                      <View style={{ flex: 1, justifyContent: 'center', paddingVertical: 16 }}>
                                              <BarChart
                                                  style={{ height: 300, }}
                                                  data={pieData}
                                                  yAccessor={({ item }) => item.value}
                                                  contentInset={{ top: 120, bottom: 5 }}
                                                  spacingInner={0.2}
                                              >
                                              {selected.value &&
                                                <Labels />
                                              }
                                              </BarChart>
                      </View>
                  )
              }

          }

          export default App

`

0reactions
AravindTReddycommented, Mar 25, 2020

@vrinch Can you please share your way around. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple Area Chart with Tooltip / Elisha Terada - Observable
I wanted to create a simple area chart with tooltip as data viz exercise and found myself Googling many resources to make this...
Read more >
Area chart with moving tooltip - GitHub Gist
Area chart with moving tooltip. GitHub Gist: instantly share code, notes, and snippets.
Read more >
plotOptions.area.tooltip | highcharts API Reference
A configuration object for the tooltip rendering of each single series. Properties are inherited from tooltip, but only the following properties can be...
Read more >
Tutorial: Stacked Area Chart
Stacked Area Chart · Stacked Area Chart with Tooltip · Stacked Area Chart with fixed Aspect Ratio · Stacked Area Chart with custom...
Read more >
Tooltips | Charts - Google Developers
Specifying the tooltip type ... Google Charts automatically creates tooltips for all core charts. They'll be rendered as SVG by default, except under...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found