Comments (6)
I think you could use the getScaledX()
and getScaledY()
APIs on SparkView
to determine where to draw your min/max labels. By default SparkAdapter.getDataBounds()
gives you back the min and max data points in your adapter.
from spark.
I did find those methods..However even after getting the floating value point how i can actually add an UI element to the existing SparkView
graph? For example: is there a method such a sparkView.setTextView(string value, float x)
or something along those lines? Or do we just use the draw(Canvas canvas)
method on the sparkView
. I am lost at how to update the SparkView
class with a new label.
from spark.
Awesome! Now you'll want to instantiate a TextView
programmatically and position it using the scaled x and y values returned from your SparkView
. SparkView is just a Sparkline so it doesn't provide the ability to add labels out-of-the-box.
from spark.
I tried the approach that you suggested. However from the documentation it seems like the SparkView
doesn't really use the x-axis
co-ordinates. It divides the x-axis
equally and simply draws a Path
along the y-axis
. That being said, wouldn't the getScaledX()
return me a pixel which is not actually used by the SparkView
. If i try the aforementioned approach, the text is not visible at all, however if i only use the getScaledY()
and then use text.setY(float y)
i see can see the text on the top left corner since that is the highest value.
Apologies if this is getting out of hand.
from spark.
Hi @pkhivesara,
@naturalwarren is right, we don't support this out of the box, but you should be able to roll-your-own here.
The x-axis behavior you mentioned can be changed. If you want spark to use the x values from your data, you can override getX()
in your SparkAdapter.
So after doing that, you can getScaledX/Y to find the spark-local coordinates of the min and max points in your data. You should be able to use those to position a TextView however you'd like. Or you could even subclass SparkView itself and draw text directly to the canvas in onDraw().
This is a fair amount of work, though, and I believe MpAndroidChart likely supports this out of the box: https://github.com/PhilJay/MPAndroidChart
from spark.
I am not sure but whenever i try to use the approach mentioned above, the text is always displayed either on top left or top right. It seems like the layout is being added against the screen width and height. Not the SparkView itself. Either ways i understand since this requirement is not part of SparkView, i will be closing the ticket. Thanks for all the help.!
from spark.
Related Issues (20)
- Does library support using List instead of float array? HOT 4
- question : support gradient color ? HOT 2
- [Request] New animation HOT 3
- Make use of Android annotations more consistent throughout library HOT 3
- Allow generic drawing effects HOT 3
- Setting cornerRadius to non-zero results in fill closing path also using radius HOT 1
- Fill with gradient HOT 3
- BaseLine dotted line sample HOT 2
- Thank you.. HOT 1
- Why doesn't onScrubbed include both x and y? HOT 6
- error: attribute spark_fillColor not found HOT 1
- Conditionally color sparkline HOT 1
- Android graph mismatch to actual charting data HOT 1
- shadow HOT 2
- Upgrade spark to androidx HOT 3
- 频繁调用notifyDataSetChanged, 导致native内存持续增高,且无法回收
- Using SparkAdapter with X and Y value and displaying both on onScrubbed() HOT 3
- can the scrubbing change from line to a button ? HOT 1
- Multiple lines in one chart? HOT 1
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 spark.