Skip to content

bandrews568/Robinhood-Chart-Clone

Repository files navigation

Robinhood Chart Clone

Combines the TickerView & SparkView libraries to mimic the functionality of the sparkline chart from the Robinhood stock trading application.

Usage

Add a RobinhoodChartClone to your view:

<github.bandrews568.robinhoodchartclone.RobinhoodChartClone
        android:id="@+id/robinhood_chart_clone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        
        <!-- Choices: positive, negative, neutral -->
        app:chart_theme="neutral" />

Displaying data is very simple:

  • Make a list with your data represented as DataPoint objects
  • call updateDataPoints(myListOfDataPoints) with that list

updateDataPoints(dataPoints: List<DataPoint>) is currently the only way to update the data points

val dataPoints: List<DataPoint> = listOf(DataPoint(34.34, 1527804000L), DataPoint(24.34, 15278044000L))
robinhood_chart_clone.updateDataPoints(dataPoints)

Determine what data to show by implementing the TimePeriodChangeListener for a callback when a radio button is checked:

class RobinhoodChartCloneSampleActivity : AppCompatActivity(), TimePeriodChangeListener {
  
  override fun onStart() {
      super.onStart()
      robinhood_chart_clone_sample.timePeriodChangeListener = this
  }
 
  override fun timePeriodChange(timePeriod: TimePeriod) {
      // Use the TimePeriod to determine the data points to display
  }
}

Reset the chart back to its default state:

robinhood_chart_clone.reset()

Installation

Add the dependency to your build.gradle.

dependencies {
    implementation 'github.bandrews568.robinhoodchartclone:robinhoodchartclone:1.0.0'
}

Libraries used

Credits

Robinhood

License

MIT