{"id":13498273,"url":"https://github.com/robinhood/spark","last_synced_at":"2025-05-16T01:05:08.741Z","repository":{"id":41092737,"uuid":"53691181","full_name":"robinhood/spark","owner":"robinhood","description":"A simple Android sparkline chart view.","archived":false,"fork":false,"pushed_at":"2023-11-23T18:01:48.000Z","size":297,"stargazers_count":1280,"open_issues_count":14,"forks_count":158,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-04-08T11:14:34.440Z","etag":null,"topics":["android","chart","graph","sparkline"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robinhood.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-11T19:21:19.000Z","updated_at":"2025-03-28T07:51:44.000Z","dependencies_parsed_at":"2024-01-14T11:18:02.974Z","dependency_job_id":null,"html_url":"https://github.com/robinhood/spark","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinhood%2Fspark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinhood%2Fspark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinhood%2Fspark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinhood%2Fspark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robinhood","download_url":"https://codeload.github.com/robinhood/spark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","chart","graph","sparkline"],"created_at":"2024-07-31T21:00:21.224Z","updated_at":"2025-05-16T01:05:03.718Z","avatar_url":"https://github.com/robinhood.png","language":"Java","funding_links":[],"categories":["图表(Chart)","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"![](images/sample.png)\n\nSpark\n======\n\n\u003e Sparkline: a very small line chart, typically drawn without axes or coordinates. It presents the\n\u003e general shape of the variation (typically over time) in some measurement, such as temperature or\n\u003e stock market price, in a simple and highly condensed way.\n\u003e\n\u003e -- [en.wikipedia.org/wiki/Sparkline](https://en.wikipedia.org/wiki/Sparkline)\n\nSpark is a simple Android library that takes a series of x,y points at any scale and draws them as a\nsparkline chart.\n\n\nUsage\n-----\n\nSpark is setup with reasonable default values out of the box. Just add a `SparkView` to your layout:\n\n```xml\n\u003cLinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\"\u003e\n\n    \u003ccom.robinhood.spark.SparkView\n        android:id=\"@+id/sparkview\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\" /\u003e\n\u003c/LinearLayout\u003e\n```\n\nThen, just give it a `SparkAdapter` to graph your data:\n\n```java\nSparkView sparkView = (SparkView) findViewById(R.id.sparkview);\nsparkView.setAdapter(new MyAdapter(data));\n...\npublic class MyAdapter extends SparkAdapter {\n    private float[] yData;\n\n    public MyAdapter(float[] yData) {\n      this.yData = yData;\n    }\n\n    @Override\n    public int getCount() {\n      return yData.length;\n    }\n\n    @Override\n    public Object getItem(int index) {\n      return yData[index];\n    }\n\n    @Override\n    public float getY(int index) {\n      return yData[index];\n    }\n}\n```\n\nSee spark-sample for a complete sample app.\n\nTheming\n-------\nSpark is very theme-friendly! It has default styles set for you, and welcomes any overrides:\n\nIn your `Activity`/`Fragment`/`View`:\n```java\nsparkView.setLineColor(getColor(R.color.brand_color_primary));\n```\n\nIn your layout xml:\n```xml\n    \u003ccom.robinhood.spark.SparkView\n        android:id=\"@+id/sparkview\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        app:spark_lineColor=\"@color/brand_color_primary\"/\u003e\n```\n\nSet a default style for all `SparkView`s in your app's theme:\n```xml\n\u003cresources\u003e\n    \u003cstyle name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\"\u003e\n        \u003citem name=\"spark_SparkViewStyle\"\u003e@style/MySparkViewStyle\u003c/item\u003e\n    \u003c/style\u003e\n\n    \u003cstyle name=\"MySparkViewStyle\" parent=\"@style/SparkView\"\u003e\n        \u003citem name=\"spark_lineColor\"\u003e@color/line_color\u003c/item\u003e\n        \u003citem name=\"spark_lineWidth\"\u003e@dimen/line_width\u003c/item\u003e\n        \u003citem name=\"spark_cornerRadius\"\u003e@dimen/corner_radius\u003c/item\u003e\n        \u003citem name=\"spark_fill\"\u003efalse\u003c/item\u003e\n\n        \u003citem name=\"spark_baseLineColor\"\u003e@color/base_line_color\u003c/item\u003e\n        \u003citem name=\"spark_baseLineWidth\"\u003e@dimen/base_line_width\u003c/item\u003e\n\n        \u003citem name=\"spark_scrubLineColor\"\u003e@color/scrub_line_color\u003c/item\u003e\n        \u003citem name=\"spark_scrubLineWidth\"\u003e@dimen/scrub_line_width\u003c/item\u003e\n        \u003citem name=\"spark_scrubEnabled\"\u003etrue\u003c/item\u003e\n\n        \u003citem name=\"spark_animateChanges\"\u003etrue\u003c/item\u003e\n    \u003c/style\u003e\n\u003c/resources\u003e\n\n```\n\nScrubbing\n---------\nScrubbing is when the user taps and drags their finger along the sparkline chart. It is very useful\nto display additional detail information about the point the user is currently scrubbing over.\n\nEnable scrubbing via xml:\n```xml\n\u003ccom.robinhood.spark.SparkView\n    ...\n    app:spark_scrubEnabled=\"true\" /\u003e\n```\n\nor programatically:\n```java\nsparkView.setScrubEnabled(true);\n```\nand then add a `SparkView.OnScrubListener` to get callbacks:\n```java\nsparkView.setScrubListener(new SparkView.OnScrubListener() {\n        @Override\n        public void onScrubbed(Object value) {\n            scrubInfoTextView.setText(getString(R.string.scrub_format, value));\n        }\n    });\n```\n\nBase Line\n---------\nIt's frequently useful to show a \"base line\" against which the rest of the sparkline chart will be\ncompared. In your `SparkAdapter`, override `hasBaseLine()` to return `true` and then return the\nappropriate base line value in `getBaseline()`.\n\nX Values\n--------\nSpark assumes that your graph's points are evenly distributed across the x-axis. If that's not true,\njust override `getX(int index)` in your `SparkAdapter` to give `SparkView` the correct value.\n\nAnimation\n---------\nTo animate sparkline changes, set an animator with `sparkView.setSparkAnimator(sparkAnimator)`.\nThere are two built-in animators: LineSparkAnimator (default) and MorphSparkAnimator. Pass your own\nimplementation to achieve custom effects.\n\nData Boundaries\n---------------\nBy default, Spark will calculate the min and max of your data set, and draw the sparkline as large as\npossible within the View boundaries. If you want different behavior, such as \"zooming in\" on a portion\nof your data, or \"zooming out\" to leave space between the sparkline and the side of the view, you\ncan override `SparkAdapter.getDataBounds()`:\n\n```java\npublic class MyAdapter extends SparkAdapter {\n    ...\n\n    @Override\n    public RectF getDataBounds() {\n        RectF bounds = super.getDataBounds();\n        // will 'zoom in' to the middle portion of the graph\n        bounds.inset(bounds.width() / 4, bounds.height() / 4);\n        return bounds;\n    }\n}\n```\n\nVision\n-------\nSpark is a very simple library and cannot possibly meet everyone's use-cases. A more robust charting\nlibrary (such as [MP Android Chart](https://github.com/PhilJay/MPAndroidChart)) may be a better fit\nif you're looking for things like axes or advanced touch gestures. Spark aims to be lightweight\nalternative for showing simple sparklines. Spark will prioritize simplicity over new use-cases the\nvast majority of the time.\n\nDownload\n--------\n\nGradle:\n\n```groovy\nimplementation 'com.robinhood.spark:spark:1.2.0'\n```\n\n\nLicense\n--------\n\n    Copyright 2016 Robinhood Markets, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinhood%2Fspark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinhood%2Fspark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinhood%2Fspark/lists"}