Skip to content

Add axis titles support#2625

Closed
xpete wants to merge 36 commits intoPhilJay:masterfrom
xpete:axistitles
Closed

Add axis titles support#2625
xpete wants to merge 36 commits intoPhilJay:masterfrom
xpete:axistitles

Conversation

@xpete
Copy link
Copy Markdown

@xpete xpete commented Dec 27, 2016

I'am using this myself on a LineChart and it's working well.
MPAndroidChart is the best chart library for Android but it's useless for me without axis titles and I think it's the most requested feature.

Related feature requests:
#2034
#1869
#716
#828
#1324
#1440
#513

Screenshot

Ewg777 and others added 19 commits October 27, 2016 08:45
Mistake fixed
The default text size in ComponentBase was defined as 10 pixels
instead of 10dp, which causes tiny text and does not reflect
the javadoc and the general behavior of setTextSize(...)
ISSUE:
When using multiple LineDataSets like the follows:

    int solidColor = 0xFFFF00FF;
    dataSet.setColor(solidColor);
    dataSet.setCircleColor(solidColor);

    int semiTransparentColor = 0x8A000000;
    fadedSet.setColor(semiTransparentColor);

    LineData data = new LineData(dataSet, fadedSet);

the circles in 'dataSet' will rendered with the alpha from
fadedSet (0x8A).

The reason for this is that mRenderPaint is not reset properly
before drawing the circles. The first time drawCircles is called
the imageCache.fill(...) method is used where the color is set by
mRenderPaint.setColor(set.getCircleColor(i)), restoring the alpha
to 0xFF. The second time homever, imageCache.fill(...) is not called
which means that mRenderPaint will use it's old color/alpha,
which in this case is from fadedSet.

TEST INFO:
To trigger the issue, add the following to LineChartActivity1:

    final ArrayList<Entry> fadedEntries = new ArrayList<>();
    for (int i = 0; i < count; i++) {

        float val = (float) (Math.random() * range) + 3;
        fadedEntries.add(new Entry(i, val));
    }
    final LineDataSet fadedDateSet = new LineDataSet(fadedEntries, "Faded");
    fadedDateSet.setColor(0x42000000);

    dataSets.add(fadedDateSet); // add the datasets

and launch the first item in the example app.

SOLUTION:
This commit replaces mRenderPaint with null when drawing the circle
bitmap. If circleColor has been defined with a semi-transparent
color, it will be drawn that way in the cached bitmap, hence the the
bitmap itself does not need to be drawn with an alpha.
Set javadoc character encoding to utf8
fix tests for java executable location in gradlew to be compatible with bash 4.3.42
Fix for default text size being set in PX instead of DP
Fixed docs typo in AxisBase.java
Copy link
Copy Markdown

@andrebstv andrebstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use some comments but overall ok.

Great feature.

@hermamitr
Copy link
Copy Markdown

I think this pull request has a bug since does not support right YAxis.

@boomsya
Copy link
Copy Markdown

boomsya commented Jul 19, 2017

I want this commit in 3.0.3 !!! :)
thanks xpete for the patch. I dont understand why this commit not included in library at now??! with no bugs :)

and yes, hermamitr, is right. Commit not drawing right axis title:
mChart.getAxisRight().setTitle("test!");

and i found 1 bug: whel legend on bottom and write mChart.getXAxis().setTitle("test!"); then xAxis title and legend at the same place :(

@xpete xpete closed this Sep 2, 2017
@xpete xpete deleted the axistitles branch September 2, 2017 20:08
@xpete
Copy link
Copy Markdown
Author

xpete commented Sep 2, 2017

I trashed this PR so I had to create a new one with the same changes:
#3399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.