androidtextsizelinempandroidchart

Does LineDataSet state gets altered by chart.setData(lineData) in MPAndroidChart?


I have a weird behavior happening to me, where I have a unique LineDataSet instance used across 2 different charts. This LineDataSet obtains its configuration BEFORE entering ANY one chart.

Both charts are of similar dimensions.

BUT one of them is resized by the Android framework.

This resizing occurs the moment a View is inflated and added to a container of different size.

In this case the container is a FrameLayout that is 100dp smaller than the original chart height and 0.85% its original match_parent width.

This is what happens...

When the first chart to receive the LineDataSet is the resized/smaller one.

The LineDataSet text and line sizes... look normal... I'd say... not big not small.

When this same dataSet is used in the second bigger chart, the line text, and line sizes are exactly equal as the first chart...

NOW IF the first chart to receive the LineDataSet is the BIGGER one, BOTH, the line AND text look extremely small.

After having .setData() to this chart, I then proceed to .setData() to the second smaller chart... the line looks exactly the same as the first chart... with every text and line extremely small.

The effect seems to be happening also in the smoothness of the BEZIER_CURVE option, as it looks more acute than what the BEZIER looks.

For reference this is what 20f .setValueTextSize( looks like when the big chart is fed first with the data (This is the perspective from the resized/smaller chart):

When big chart is fed first (this is the resized chart)

And this is how 20f looks when the resized/smaller chart is fed first (This is the perspective from the resized/smaller chart):

When resized chart is fed first (this is the resized chart)

This is text of size 9f, when the big chart is fed first (This is the perspective from the big chart):

text size = 9f, on big chart fed first. (this is the BIG chart)

This is the small/resized chart when the BIG chart is fed first with text of 9f:

text of 9f when BIG chart is fed first (seen from the resized chart perspective)

When 9f is fed to the smaller/resized chart first... everything looks fine.

This is happening across different Android versions also.

Is this an Android thing or is it because the DataSet is keeping some size parameter within itself?


Solution

  • The issue arised because the LineDataSet was being built before the Chart was even initialized, as such, a private static field called "mMetrics" of type DisplayMetrics.class. (a class that helps convert the float into a value that matches the device display metrics), was not being initialized.

    My solution was to call:

    Utils.init(getApplication());
    

    In a place I was sure to be called once.