robinhood / spark

A simple Android sparkline chart view.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filling Graph With Negative Data Fills Under the Line Instead of Over It

Sub6Resources opened this issue · comments

I have a graph that needs to use all negative data, and I was trying to fill the inside of the data.

When I set shading to true using setFill(true), my graph with all negative data looks like this (the baseline you can see is at 0):

screenshot_20170609-194201 1

As you can see, the fill is placed underneath the line, instead of above it, as you would expect, which makes all the data look positive. To fix this in my own app, I had to do this:
sparkView.setLineColor(getResources().getColor(R.color.colorBackground));
sparkView.setBackgroundColor(getResources().getColor(R.color.colorAccent));

I set the background color to my line color, and the line color to my background color. As you can see, this works (the baseline is again at 0):

screenshot_20170609-195053 1

But obviously it would be a whole lot nicer if it worked without the hack I had to implement. 😉
Thanks!

Ah, interesting use case. I hadn't given much thought to having the fill be 'toward zero' instead of just downward. I can see how some might still want negative values to fill like they are right now (say temperature values in winter), so I'd have to make this configurable somehow.