Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

series with titel null will not be shown in the legend #494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/java/com/jjoe64/graphview/LegendRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,15 @@ public void draw(Canvas canvas) {
}
}

int SeriesWithLegendCount = 0;
for (Series s : allSeries) {
if (s.getTitle() != null) {
SeriesWithLegendCount++;
}
}

// rect
float legendHeight = (mStyles.textSize+mStyles.spacing)*allSeries.size() -mStyles.spacing;
float legendHeight = (mStyles.textSize+mStyles.spacing)*SeriesWithLegendCount -mStyles.spacing;
float lLeft;
float lTop;
if (mStyles.fixedPosition != null) {
Expand All @@ -217,13 +224,13 @@ public void draw(Canvas canvas) {

int i=0;
for (Series series : allSeries) {
mPaint.setColor(series.getColor());
canvas.drawRect(new RectF(lLeft+mStyles.padding, lTop+mStyles.padding+(i*(mStyles.textSize+mStyles.spacing)), lLeft+mStyles.padding+shapeSize, lTop+mStyles.padding+(i*(mStyles.textSize+mStyles.spacing))+shapeSize), mPaint);
if (series.getTitle() != null) {
mPaint.setColor(series.getColor());
canvas.drawRect(new RectF(lLeft+mStyles.padding, lTop+mStyles.padding+(i*(mStyles.textSize+mStyles.spacing)), lLeft+mStyles.padding+shapeSize, lTop+mStyles.padding+(i*(mStyles.textSize+mStyles.spacing))+shapeSize), mPaint);
mPaint.setColor(mStyles.textColor);
canvas.drawText(series.getTitle(), lLeft+mStyles.padding+shapeSize+mStyles.spacing, lTop+mStyles.padding+mStyles.textSize+(i*(mStyles.textSize+mStyles.spacing)), mPaint);
i++;
}
i++;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jjoe64/graphview/series/BaseSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public String getTitle() {
/**
* set the title of the series. This will be used in
* the legend.
* Use null if you want to hide the legend entry
*
* @param mTitle title of the series
*/
Expand Down