robinhood / spark

A simple Android sparkline chart view.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fill Color

sijangurung opened this issue · comments

How do we define a fill color ? I am trying to create a graph with white line and gradient fill color ..so trying to override the SparkView , but it not able to do so ! Help

Unfortunately, we don't have anything built in directly for you to set both a stroke color and a fill color. We recently added a way for you to get a Path object representing the graph, though, so you can use this to do what you're asking. You'll need to do a couple of things:

  1. Depend on the latest snapshot in your build.gradle:
compile 'com.robinhood.spark:spark:1.1.1-SNAPSHOT'

Then you'll have access to the new method sparkView.getSparkLinePath() to be able to do some custom drawing.

  1. Next, create a subclass of SparkView in your project to handle the extra drawing step:
public class StrokeAndFillSparkView extends SparkView {
  private Paint strokePaint;

  public StrokeAndFillSparkView(...) {
    ...
    strokePaint = new Paint(...);
    // modify strokePaint to have your stroke color

    // configure the spark line's paint to fill 
    setFill(true); // can set via xml/styles instead if desired
    Paint fillPaint = getSparkLinePaint();
    LinearGradient gradient = new LinearGradient(...);
    fillPaint.setShader(gradient);
  }

  @Override
  public void onDraw(Canvas canvas) {
    // the normal draw call, will handle drawing the path filled in with your gradient
    super.onDraw(canvas);

    // next, draw your custom stroke on top of that
    Path path = getSparkLinePath();
    canvas.drawPath(path, strokePaint);
  }
}
  1. Now, just use your subclass instead of the normal SparkView

Hope this helps!

Hei Dan,

First of all, thanks for the answer.
I did implement as you suggested. And with more or less changes, I got the output that I need.
Thanks for the library and thanks for the response.

I had added screenshot of my CustomView for you, and also I was wondering , when are you guys planning to release the latest version (1.1.1), since I wanted to use the final release version, rather than SNAPSHOT one.

Good luck for the release and Thanks for the awesome works.

Warms Regards,
Sijan Gurung
Developer
Oslo, Norway

On 30 May 2016, at 23:19, Dan Hill notifications@github.com wrote:

Unfortunately, we don't have anything built in directly for you to set both a stroke color and a fill color. We recently added a way for you to get a Path object representing the graph, though, so you can use this to do what you're asking. You'll need to do a couple of things:

  1. Depend on the latest snapshot in your build.gradle:

compile 'com.robinhood.spark:spark:1.1.1-SNAPSHOT'
Then you'll have access to the new method sparkView.getSparkLinePath() to be able to do some custom drawing.

  1. Next, create a subclass of SparkView in your project to handle the extra drawing step:

public class StrokeAndFillSparkView extends SparkView {
private Paint strokePaint;

public StrokeAndFillSparkView() {
...
strokePaint = new Paint(...);
// modify strokePaint to have your stroke color

// configure the spark line's paint to fill 
setFill(true); // can set via xml/styles instead if desired
Paint fillPaint = getSparkLinePaint();
LinearGradient gradient = new LinearGradient(...);
fillPaint.setShader(gradient);

}

@OverRide
public void onDraw(Canvas canvas) {
// the normal draw call, will handle drawing the path filled in with your gradient
super.onDraw(canvas);

// next, draw your custom stroke on top of that
Path path = getSparkLinePath();
canvas.drawPath(path, strokePaint);

}
}
3) Now, just use your subclass instead of the normal SparkView

Hope this helps!


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #15 (comment), or mute the thread https://github.com/notifications/unsubscribe/AEO1bhiBkF-YFlYNzr9a9yJHbAxyWcuIks5qG1RPgaJpZM4Ipuzh.

Hi Sijan,

Glad you got it working!

We're hoping to release 1.1.1 in a couple of weeks.

Thanks!