All Projects → robinhood → Spark

robinhood / Spark

Licence: apache-2.0
A simple Android sparkline chart view.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Spark

React D3 Tree
🌳 React component to create interactive D3 tree graphs
Stars: ✭ 543 (-53.9%)
Mutual labels:  graph, chart
Uplot
📈 A small, fast chart for time series, lines, areas, ohlc & bars
Stars: ✭ 6,808 (+477.93%)
Mutual labels:  graph, chart
Esp Dash
A blazing fast library to create a functional dashboard for ESP8266 and ESP32
Stars: ✭ 548 (-53.48%)
Mutual labels:  graph, chart
Piecharts
Easy to use and highly customizable pie charts library for iOS
Stars: ✭ 476 (-59.59%)
Mutual labels:  graph, chart
Ilg
because the world needs another iOS chart library.
Stars: ✭ 13 (-98.9%)
Mutual labels:  graph, chart
Billboard.js
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Stars: ✭ 5,032 (+327.16%)
Mutual labels:  graph, chart
Asciichart
Nice-looking lightweight console ASCII line charts ╭┈╯ for NodeJS, browsers and terminal, no dependencies
Stars: ✭ 1,107 (-6.03%)
Mutual labels:  graph, chart
Flutter Candlesticks
Elegant OHLC Candlestick and Trade Volume charts for @Flutter
Stars: ✭ 318 (-73.01%)
Mutual labels:  graph, chart
Chart.xkcd
Chart.xkcd is a chart library that plots “sketchy”, “cartoony” or “hand-drawn” styled charts.
Stars: ✭ 6,982 (+492.7%)
Mutual labels:  graph, chart
Multi charts
A flutter package which makes it easier to plot different types of charts with lots of customization, made purely in dart
Stars: ✭ 23 (-98.05%)
Mutual labels:  graph, chart
Vue D3 Network
Vue component to graph networks using d3-force
Stars: ✭ 415 (-64.77%)
Mutual labels:  graph, chart
Pure Vue Chart
Simple and lightweight vue chart component without using chart library dependencies
Stars: ✭ 50 (-95.76%)
Mutual labels:  graph, chart
Androidplot
Charts and plots for Android
Stars: ✭ 381 (-67.66%)
Mutual labels:  graph, chart
Ttyplot
a realtime plotting utility for terminal/console with data input from stdin
Stars: ✭ 532 (-54.84%)
Mutual labels:  graph, chart
Tplink Energy Monitor
An energy monitoring dashboard for TP-Link smart plugs
Stars: ✭ 316 (-73.17%)
Mutual labels:  graph, chart
Gojs
JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
Stars: ✭ 5,739 (+387.18%)
Mutual labels:  graph, chart
Fl chart
A powerful Flutter chart library, currently supporting Line Chart, Bar Chart, Pie Chart, Scatter Chart and Radar Chart.
Stars: ✭ 3,882 (+229.54%)
Mutual labels:  graph, chart
Sparklinelayout
Simple and lightweight library for drawing sparklines / graphs. Support markers and gradients.
Stars: ✭ 291 (-75.3%)
Mutual labels:  graph, chart
Amcharts4
The most advanced amCharts charting library for JavaScript and TypeScript apps.
Stars: ✭ 907 (-23.01%)
Mutual labels:  graph, chart
Mpandroidchart
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Stars: ✭ 34,377 (+2818.25%)
Mutual labels:  graph, chart

Spark

Sparkline: a very small line chart, typically drawn without axes or coordinates. It presents the general shape of the variation (typically over time) in some measurement, such as temperature or stock market price, in a simple and highly condensed way.

-- en.wikipedia.org/wiki/Sparkline

Spark is a simple Android library that takes a series of x,y points at any scale and draws them as a sparkline chart.

Usage

Spark is setup with reasonable default values out of the box. Just add a SparkView to your layout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.robinhood.spark.SparkView
        android:id="@+id/sparkview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Then, just give it a SparkAdapter to graph your data:

SparkView sparkView = (SparkView) findViewById(R.id.sparkview);
sparkView.setAdapter(new MyAdapter(data));
...
public class MyAdapter extends SparkAdapter {
    private float[] yData;

    public MyAdapter(float[] yData) {
      this.yData = yData;
    }

    @Override
    public int getCount() {
      return yData.length;
    }

    @Override
    public Object getItem(int index) {
      return yData[index];
    }

    @Override
    public float getY(int index) {
      return yData[index];
    }
}

See spark-sample for a complete sample app.

Theming

Spark is very theme-friendly! It has default styles set for you, and welcomes any overrides:

In your Activity/Fragment/View:

sparkView.setLineColor(getColor(R.color.brand_color_primary));

In your layout xml:

    <com.robinhood.spark.SparkView
        android:id="@+id/sparkview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:spark_lineColor="@color/brand_color_primary"/>

Set a default style for all SparkViews in your app's theme:

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="spark_SparkViewStyle">@style/MySparkViewStyle</item>
    </style>

    <style name="MySparkViewStyle" parent="@style/SparkView">
        <item name="spark_lineColor">@color/line_color</item>
        <item name="spark_lineWidth">@dimen/line_width</item>
        <item name="spark_cornerRadius">@dimen/corner_radius</item>
        <item name="spark_fill">false</item>

        <item name="spark_baseLineColor">@color/base_line_color</item>
        <item name="spark_baseLineWidth">@dimen/base_line_width</item>

        <item name="spark_scrubLineColor">@color/scrub_line_color</item>
        <item name="spark_scrubLineWidth">@dimen/scrub_line_width</item>
        <item name="spark_scrubEnabled">true</item>

        <item name="spark_animateChanges">true</item>
    </style>
</resources>

Scrubbing

Scrubbing is when the user taps and drags their finger along the sparkline chart. It is very useful to display additional detail information about the point the user is currently scrubbing over.

Enable scrubbing via xml:

<com.robinhood.spark.SparkView
    ...
    app:spark_scrubEnabled="true" />

or programatically:

sparkView.setScrubEnabled(true);

and then add a SparkView.OnScrubListener to get callbacks:

sparkView.setScrubListener(new SparkView.OnScrubListener() {
        @Override
        public void onScrubbed(Object value) {
            scrubInfoTextView.setText(getString(R.string.scrub_format, value));
        }
    });

Base Line

It's frequently useful to show a "base line" against which the rest of the sparkline chart will be compared. In your SparkAdapter, override hasBaseLine() to return true and then return the appropriate base line value in getBaseline().

X Values

Spark assumes that your graph's points are evenly distributed across the x-axis. If that's not true, just override getX(int index) in your SparkAdapter to give SparkView the correct value.

Animation

To animate sparkline changes, set an animator with sparkView.setSparkAnimator(sparkAnimator). There are two built-in animators: LineSparkAnimator (default) and MorphSparkAnimator. Pass your own implementation to achieve custom effects.

Data Boundaries

By default, Spark will calculate the min and max of your data set, and draw the sparkline as large as possible within the View boundaries. If you want different behavior, such as "zooming in" on a portion of your data, or "zooming out" to leave space between the sparkline and the side of the view, you can override SparkAdapter.getDataBounds():

public class MyAdapter extends SparkAdapter {
    ...

    @Override
    public RectF getDataBounds() {
        RectF bounds = super.getDataBounds();
        // will 'zoom in' to the middle portion of the graph
        bounds.inset(bounds.width() / 4, bounds.height() / 4);
        return bounds;
    }
}

Vision

Spark is a very simple library and cannot possibly meet everyone's use-cases. A more robust charting library (such as MP Android Chart) may be a better fit if you're looking for things like axes or advanced touch gestures. Spark aims to be lightweight alternative for showing simple sparklines. Spark will prioritize simplicity over new use-cases the vast majority of the time.

Download

Gradle:

implementation 'com.robinhood.spark:spark:1.2.0'

License

Copyright 2016 Robinhood Markets, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].