Using SparkAdapter with X and Y value and displaying both on onScrubbed()
ndrb opened this issue · comments
Hello,
Thank you for this great and easy to use library!
I was wondering how I can use SparkAdapter to it's full extent.
I have both X and Y value with Y being the price of the asset, and X the time.
When the sparkline is clicked and onScrubbed is triggered I want to update the scrubInfoTextView with both values of X and Y. I am not too certain how to do that using the spark adapter.
public class AssetAdapter extends SparkAdapter {
private float[] yData;
public float[] xData;
public CryptoAdapter(float[] yData) {
this.yData = yData;
}
@Override
public int getCount() {
return yData.length;
}
@Override
public Object getItem(int index) {
return yData[index];
}
@Override
public float getY(int index) {
return yData[index];
}
@Override
public float getX(int index) { return xData[index];}
}
public void setupSpark()
{
sparkView = findViewById(R.id.sparkview);
sparkView.setAdapter(adapter);
sparkView.setScrubListener(new SparkView.OnScrubListener()
{
@Override
public void onScrubbed(Object value) {
if (value == null) {
scrubInfoTextView.setText(R.string.scrub_empty);
} else {
scrubInfoTextView.setText(getString(R.string.scrub_format, value));
}
}
});
sparkView.setScrubLineWidth(0);
sparkView.setScrubLineColor( getResources().getColor(R.color.colorPrimaryDark) );
scrubInfoTextView = findViewById(R.id.scrub_info_textview);
}
In the SparkView class, there is a method: public void onScrubbed(float x, float y)
but when I try to override it cannot find that method.
I'm also interested if we can do that. I'm looking to display secondary data (in our case the time) apart from the data that's given for making the line.
Great, thanks