Code Monkey home page Code Monkey logo

Comments (6)

naturalwarren avatar naturalwarren commented on June 17, 2024

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.

pkhivesara avatar pkhivesara commented on June 17, 2024

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.

naturalwarren avatar naturalwarren commented on June 17, 2024

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.

pkhivesara avatar pkhivesara commented on June 17, 2024

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.

danh32 avatar danh32 commented on June 17, 2024

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.

pkhivesara avatar pkhivesara commented on June 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.