Android Question xChart Format MeanLine Value Decimals and Display xAxis Every Other Value

Mahares

Expert
Licensed User
Longtime User
I use the latest xChart Class: Version 2.6 2018.11.04 for BAR chart, but could not locate the 2 below needs in the Class module:
  1. For a BAR graph, I use the following to add a mean y value line:
B4X:
chart.IncludeBarMeanLine=True 
chart.MeanLineColor=Colors.DarkGray
When it displays the mean value, can I display the mean value by formatting it to show say 1 decimal instead of 5: ex: show 1.7 instead of 1.666672.

2. When there are several x values to plot, the x axis gets cluttered. The way I do it is to skip x values my using the Mod operator to show every other x value. Is there a way to make every other or every n X values visibility false to unclutter the X axis
Thank you
 

klaus

Expert
Licensed User
Longtime User
The latest version is 2.7.

1.1 chart.IncludeBarMeanLine=True there was an error in the code which changed the property, amended for version 2.8.
To correct it, remove this line in the xChart class module: Graph.IncludeBarMeanLine = Props.Get("IncludeMeanLine")
1.2 The Bar mean line color is the bar color, as it is valid only for single bar charts.
The MeanLineColor property is thought only for the single line chart, therefore it has no effect in the Bar chart.
Do you really need it ?
1.3 The default formatting displays 6 digits. I will think about it and look to add a CustomFormat.

2. What do you mean with 'clutterd', can you show me an example?
In version 2.7 the x scale display was improved avoiding text overlapping, vertical lines are drawn for every ShowTick = True, but the values are drawn only if there is enough place.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What do you mean with 'clutterd', can you show me an example?
@klaus: I have attached a snapshot of a cluttered xAxis. Also see the mean value showing several digits.
The latest version is 2.7.

I got the error shown in the other snapshot when I upgraded to version 2.7 because I am using the example and class modified by Erel in the following thread in post #17:
https://www.b4x.com/android/forum/threads/xchart-on-xcustomlistview-trouble.98938/
 

Attachments

  • xChartCrowdedxAxis111318.png
    xChartCrowdedxAxis111318.png
    188.9 KB · Views: 324
  • ErrorUsingxChartClass270.png
    ErrorUsingxChartClass270.png
    67.7 KB · Views: 302
Upvote 0

klaus

Expert
Licensed User
Longtime User
For version 2.7, change Private xBase As B4XView to Public xBase As B4XView. Amended in version 2.8.
Can you please try your project with version 2.7, with the modification above, for the X axis.
You could also set the text sizes manually for small charts. Uncheck AutomaticTextSizes and set the indivdual sizes.
The image is not really good, but it seems that the Y axis doesn't look good either, here you should change the NbYIntervals property and / or the text sizes.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
For version 2.7, change Private xBase As B4XView to Public xBase As B4XView. Amended in version 2.8.
Can you please try your project with version 2.7, with the modification above, for the X axis.
I changed to 2.70 as per your instructions and now it works well. It skips displaying every other x value if crowded which makes is look good. I presume you have not yet uploaded version 2.80
you should change the NbYIntervals property and / or the text sizes.
chart.NbYIntervals=5 'works well to unclutter the Yaxis
The only thing left to put the finishing touches is to be able to adjust the decimals in the mean Yvalue, although I can live without.
@klaus: Tu es absolument magnifique
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The xChart class has been updated to version 2.8 in the first post HERE.
Version 2.80 corrected the issue and looks great.
1. I attached a snapshot for a case where there is no data (all Yvalues are 0), the Yaxis displays: NaNeNaNe. Can we just leave that blank as it adds nothing to the graph.
2. As you mentioned: chart.MeanLineColor=Colors.Red does not work, so the mean line color inherits the graph color. The only problem with using the same color is that it blends in with the bars colors and does not stand out. If it is not possible to make it work, that is ok.
Your knowledge is exponential to your age.
 

Attachments

  • xChartDIsplay111418.png
    xChartDIsplay111418.png
    63.6 KB · Views: 279
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Mahares,
I hadn't modified the mean line color because in post #2 I asked: Do you really need it?
As you didn't answer, I didn't modify it, thinking no real need.

Can you please test the attached xChart.bas file version 2.9.
I will update it in the xChart thread when it is OK, no other bugs, there is no hurry.

When all values are equal to 0 then no Y scale is drawn.
Another solution would be to set a 0 to 1 scale.
What do you prefer?
 

Attachments

  • xChart.bas
    87.9 KB · Views: 300
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Can you please test the attached xChart.bas file version 2.9.
Bonjour @klaus:
I tested the new pre-production class 2.90 and it looks good. The Yvalue axis is blank when all Yvalues are 0. which is the preferred way. That is the way you have it.
The meanline color is also changed in 2.90 and looks really good.
I cannot think of anything else at this stage, unless you and any others see potential enhancements.
Thank you very much
 
Upvote 0
Top