BarChart ライブラリはわかりませんが、独自に実装するのは非常に簡単です。最近作成したもののスニペットを貼り付けます。これがお役に立てば幸いです。
package com.example.preferencestest.util;
import com.example.preferencestest.R;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class MyCustomChartView extends View {
private int width=0, height=0;
public MyCustomChartView(Context context) {
super(context);
setup(null);
}
public MyCustomChartView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setup(attrs);
}
public MyCustomChartView(Context context, AttributeSet attrs) {
super(context, attrs);
setup(attrs);
}
private int firstValue=0, secondValue=0, thirdValue=0, horizontalPadding=20, verticalPadding=40;
private String title="";
private Paint outerLine, grid, other;
private Resources res;
private void setup(AttributeSet attrs) {
if (attrs != null) {
Context ctx = getContext();
TypedArray ta = ctx.obtainStyledAttributes(attrs, R.styleable.MyCustomCharView);
firstValue = ta.getInt(R.styleable.MyCustomCharView_Plot_First_Value, firstValue);
secondValue = ta.getInt(R.styleable.MyCustomCharView_Plot_Second_Value, secondValue);
thirdValue = ta.getInt(R.styleable.MyCustomCharView_Plot_Third_Value, thirdValue);
ta.recycle();
}
res = getResources();
outerLine = new Paint(Paint.ANTI_ALIAS_FLAG);
outerLine.setColor(res.getColor(R.color.plot_outer_line));
outerLine.setStrokeWidth(3);
grid = new Paint(Paint.ANTI_ALIAS_FLAG);
grid.setColor(res.getColor(R.color.plot_grid));
grid.setStrokeWidth(2);
other = new Paint(Paint.ANTI_ALIAS_FLAG);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w; height = h;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//float width = canvas.getWidth(), height = canvas.getHeight();
int limit = Math.max(6, Math.max(firstValue, Math.max(secondValue, thirdValue)));
canvas.drawLine(horizontalPadding, verticalPadding,
horizontalPadding, height-verticalPadding, outerLine);
canvas.drawLine(horizontalPadding, height-verticalPadding,
width-horizontalPadding, height-verticalPadding, outerLine);
int gridVertMargin = Math.round((height-(verticalPadding*2))/7);
for (int i=0; i<7; i++) {
canvas.drawLine(horizontalPadding+1,
verticalPadding+(i*gridVertMargin),
width-horizontalPadding,
verticalPadding+(i*gridVertMargin), grid);
}
int gridHoriMargin = Math.round((width-(horizontalPadding*2))/limit);
for (int i = 0; i < limit; i++) {
canvas.drawLine(horizontalPadding+((i+1)*gridHoriMargin),
verticalPadding+1,
horizontalPadding+((i+1)*gridHoriMargin),
height-verticalPadding, grid);
canvas.drawText(String.valueOf(i+1), horizontalPadding+((i+1)*gridHoriMargin)-2, height-(verticalPadding/2), outerLine);
}
other.setColor(res.getColor(R.color.plot_first_color));
if (this.firstValue > 0) {
canvas.drawRect(horizontalPadding+1,
verticalPadding+(gridVertMargin*1)+1,
this.firstValue*gridHoriMargin+horizontalPadding-1,
verticalPadding+(gridVertMargin*2)-1, other);
}
other.setColor(res.getColor(R.color.plot_second_color));
if (this.secondValue > 0) {
canvas.drawRect(horizontalPadding+1,
verticalPadding+(gridVertMargin*3)+1,
this.secondValue*gridHoriMargin+horizontalPadding-1,
verticalPadding+(gridVertMargin*4)-1, other);
}
other.setColor(res.getColor(R.color.plot_third_color));
if (this.thirdValue > 0) {
canvas.drawRect(horizontalPadding+1,
verticalPadding+(gridVertMargin*5)+1,
this.thirdValue*gridHoriMargin+horizontalPadding-1,
verticalPadding+(gridVertMargin*6)-1, other);
}
}
public int getFirstValue() {
return firstValue;
}
public void setFirstValue(int first) {
if (this.firstValue != first) {
this.firstValue = first;
invalidate();
}
}
public int getSecondValue() {
return secondValue;
}
public void setSecondValue(int second) {
if (this.secondValue != second) {
this.secondValue = second;
invalidate();
}
}
public int getThirdValue() {
return thirdValue;
}
public void setThirdValue(int third) {
if (this.thirdValue != third) {
this.thirdValue = third;
invalidate();
}
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
if (! this.title.equals(title)) {
this.title = title;
invalidate();
}
}
}
次のような xml スタイル設定可能な値 (この場合は 1 番目、2 番目、3 番目のバー) の xml ファイルが必要になります。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomCharView">
<attr name="Plot_First_Value" format="integer" />
<attr name="Plot_Second_Value" format="integer" />
<attr name="Plot_Third_Value" format="integer" />
</declare-styleable>
<color name="plot_outer_line">#330000</color>
<color name="plot_grid">#dd0000</color>
<color name="plot_first_color">#99aa00</color>
<color name="plot_second_color">#770000</color>
<color name="plot_third_color">#00ee77</color>
</resources>
最後に、次のように新しい BarChart をレイアウトに追加できます。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res/[yourpackage]">
<[yourpackage].MyCustomChartView
android:id="@+id/row_plot"
style="@style/ListItem"
android:layout_width="match_parent"
android:layout_height="150dp"
title=""
app:Plot_First_Value="15"
app:Plot_Second_Value="1"
app:Plot_Third_Value="3" />
{...}