B4J Library [B4X] [XUI] xChart Class and b4xlib

Knoppi

Active Member
Licensed User
Longtime User
Hi Klaus,
I have downloaded version 6.60 from the first post.
it is not possible to set the ChartType to "H_BAR" by code
B4X:
Public Sub setChartType(ChartType As String)
    If ChartType = "BAR" Or ChartType = "STACKED_BAR" Or ChartType = "LINE" Or ChartType = "PIE" Or ChartType = "RADAR" Then
        Graph.ChartType = ChartType
    Else
        Log("Wrong chart type")
    End If
End Sub
the query to H_BAR is missing here ( class and b4xlib)
B4X:
Public Sub setChartType(ChartType As String)
    If ChartType = "H_BAR" Or ChartType = "BAR" Or ChartType = "STACKED_BAR" Or ChartType = "LINE" Or ChartType = "PIE" Or ChartType = "RADAR" Then
        Graph.ChartType = ChartType
    Else
        Log("Wrong chart type")
    End If
End Sub
Viele Grüße, Knoppi
 

Knoppi

Active Member
Licensed User
Longtime User
Hi Klaus,
am I doing something wrong or the library has a bug?

If you only use one layout and switch back and forth between the charts,
an error occurs with the cursor display bar.


Viele Grüße, Knoppi

I've attached a small example (B4J 8.80, xChart 6.60 with modifikation Post #362)
 

Attachments

  • xChart.zip
    3.5 KB · Views: 241

Knoppi

Active Member
Licensed User
Longtime User
Hi Klaus,

in setChartype the entries "H_STACKED_BAR" and "YX_CHART" are also missing .

Thanks for this great tool.

Viele Grüße, Knoppi

ps: Is it also possible to create an area diagram ?
like this: area diagram
 

klaus

Expert
Licensed User
Longtime User
in setChartype the entries "H_STACKED_BAR" and "YX_CHART" are also missing .
It is already amended in my latest version not published yet.

ps: Is it also possible to create an area diagram ?
No, and it is not in the pipe line.

Currently, I am working on the class, the next version will be published in a few days.
 

klaus

Expert
Licensed User
Longtime User
xChart has been updated to Version 6.7 in the first post.

Added two methods:
AddHorizontalLine(Value) adds a line which is drawn at the given value
RemoveHorizontalLine(Value) removes the line from the List
Added five properties:
YXChartDisplayValues, displays the coordinates of the cursor positions on YXCharts
YXChartDisplayPosition, position of the display on the YXChart.
YXChartDisplayCrossHair, displays the cursor positions as a cross hair cursor on YXCharts
YXChartCrossHairColor, color for the cross hair cursor on YXCharts
YXChartCrossHairDeltaY, the horizontal line of the cross hair cursor is shifted topwards by the given value only for YX_CHARTs
this is useful to not cover the horizontal cursor line with the finger
 

madru

Active Member
Licensed User
Longtime User


Hi Klaus,

any change to reposition the Value if 0 (zero) a little higher, please see screenshot of BarChart.AddBarMultiplePoint

 

madru

Active Member
Licensed User
Longtime User
Hi Klaus,

I have a BarMultiplePoint (3 values) per day of the month and the values are not drawn because the bars are to narrow. Any change to force drawing the values?
also is it possible to have some space between the bars for a BarMultiplePoint?

I would like the Excel behaviour as shown in the 3rd picture

The B4XChart


the missing space


the original Excel graph
 

madru

Active Member
Licensed User
Longtime User
Hi Peter,

did some testing, looks like it doesn't work to set the Y max value or I am doing it wrong?!

something like
B4X:
Bar.YMaxValue=500
will be amended
 
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
Hello All,

@klaus :
I started to try your class on B4J, who's really great, thank you ?

As i'm interested to use the XYChart, but with the YXChartIndex = 2 example, i saw there are missing points, looks screenshot below:


So, i investigated a bit your class to try to understand why, maybe i found a bug, i put you the code below the picture. :
In the Sub "DrawYXLines" there are 2 boucles, 1st one with an index l and the 2nd with index i.
It seems the test is did on the bad ref. "Items.size-1" who is always 2, the X and Y positions i think
I corrected with "ID.YXArray.Size - 1 and that seems to match better, but stay 2 missing points, see screenshot below:


The code modified, the supposed bug is at line 3168 in original project :
B4X:
Private Sub DrawYXLines
   .../... Nothing changed .../...
    For l = 0 To Items.Size - 1            '< 1st boucle
.../... Nothing changed .../...
        For i = 0 To ID.YXArray.Size - 1        '< 2nd boucle
            If ID.PointType <> "NONE" Then
                'Added to control the 2 sizes, ID.YXArray.Size match better but stay missing points, with Items.Size-1 more missing points ?
                Log("i = Items.Size - 1 ? " & " i=" & i & " Items.Size-1=" & (Items.Size-1))
                Log("ID.YXArray.Size-1: " & (ID.YXArray.Size-1))
                'Uncomment for original code and comment the 2nd line below
                'If i = Items.Size- 1 Then                 'Missing points on XYChart, tested when YXChartIndex = 2
                If i = ID.YXArray.Size - 1 Then         'A bit better, only 2 missing points, but still have, i even don't understand why :(
                    DrawPoint(x1, y1, ID.PointColor, ID.PointType, ID.Filled, ID.StrokeWidth)
                Else
                    DrawPoint(x0, y0, ID.PointColor, ID.PointType, ID.Filled, ID.StrokeWidth)
                End If
            End If
            x0 = x1
            y0 = y1
        Next
    Next
.../... Nothing changed .../...    
End Sub

As i didn't tested that on B4A and B4I, i haven't B4I, and because the 2 points who stay missing, i prefer to submit you my result, if ever i'm not too bad i hope that help.

Have a nice weekend.
 

klaus

Expert
Licensed User
Longtime User
I have a BarMultiplePoint (3 values) per day of the month and the values are not drawn because the bars are to narrow. Any change to force drawing the values?
also is it possible to have some space between the bars for a BarMultiplePoint?
I had a look at your suggestion.
I saw that the drawing of multibar charts was not good, the bars width was too low.
I made following changes:
Improved the multibar charts drawing, the bar widths are wider, I will not add spaces between the bars I only leave a small space between bar groups.
Decreased the minimum text size of the values in the bars.
I will not change the drawing of the bar values like in the Excel chart, because with bigger numbers it will become messy.



EDIT: 2021.03.15
Removed the xChart.b4xlib and xChart.bas files, they have been updated in the first post.

As i'm interested to use the XYChart, but with the YXChartIndex = 2 example, i saw there are missing points, looks screenshot below:
Merci for reporting this.
Your suggestion is one part of the final solution.
Amended in version 6.9.



The code change:

B4X:
For i = 1 To ID.YXArray.Size - 1
    yxVal = ID.YXArray.Get(i)
    If Scale(sX).Logarithmic = False Then
        x1 = Graph.Left + (yxVal(0) - Scale(sX).MinVal) * Scale(sX).Scale
    Else
        x1 = xi + Logarithm(yxVal(0), 10) * ScaleLog(sX).Scale
    End If
    If Scale(sY(0)).Logarithmic = False Then
        y1 = Graph.Bottom - (yxVal(1) - Scale(sY(0)).MinVal) * Scale(sY(0)).Scale
    Else
        y1 = yi - Logarithm(yxVal(1), 10) * ScaleLog(sY(0)).Scale
    End If
    If ID.DrawLine = True Then
        xcvsGraph.DrawLine(x0, y0, x1, y1 , ID.Color, ID.StrokeWidth)
    End If
        If ID.PointType <> "NONE" Then
            DrawPoint(x0, y0, ID.PointColor, ID.PointType, ID.Filled, ID.StrokeWidth)
            If i = ID.YXArray.Size - 1 Then
                DrawPoint(x1, y1, ID.PointColor, ID.PointType, ID.Filled, ID.StrokeWidth)
            End If
        End If
    x0 = x1
    y0 = y1
Next

Can you please check these changes before I publish this new version.
 
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
Good morning,

@klaus
Merci for reporting this.
Your suggestion is one part of the final solution.
Amended in version 6.9.
You're welcome, i was quite sure i had not solved all, it stayed 2 missing points.
Better to ask to God than his Saints as we're habit to say in France ?

Can you please check these changes before I publish this new version.
Perfect, thank you. Below screenshot from B4J, i would see in B4A when i would finish to adapt my project.
But no reason that it'll not work the same.

Thank you very much Klaus, results are wonderfull and it's very fast to have the chart even with a SQL request on a big datbase, congrats for this great library.

Have a nice Sunday,
Laurent.
 

Laurent95

Active Member
Licensed User
Longtime User
Hi all,

Another question, but not only to Klaus, any help is welcome ?

I work on my currencies exchange rates converter, that i need to adapt with the new features on B4x, It's an old widget i did long time ago. But since Google harassed me with many asking on some private things i deleted my Google developper account.
So now i want to renew it and i will publish results here under B4A and B4J. Sorry but i haven't B4I, Apple give me buttons especially with prices, i hate the GAFAMs ?

The idea is to use YXChart when there are more than 3 months of rates history, the BCE give a lot or exchange rates, i've all since 1999 ?. But when there are more than 3 months the chart start to be not really lisible, too much data (especially for my poor old eyes).
As a picture is more comprehensive than a complexe explanation, see below, and it's only 6 months, worst on 1 year... :


So i think it would be possible to put average by month, but keep also for each month, the min and max of exchange rate, it's why the YXChart, to have the curve of min and max too.
On some currencies the exchange rate varies a lot with an average who's not always enough representative. Difficult to keep a balanced result between too much data and a lisible result
My question is : How i can keep the name of X axis, who's the date on picture below (A String, and the months in case of YXChart) ?
The Picture below is a lineChart


I'm not sure that i can use "SingleLine1.AddLinePointData" it's specified only for the line chart.
Can we do the same on YXChart like i use with success on a LineChart under 3 months ?
Sorry if i didn't see what is evident but the work of Klaus is really big now, and i start only to study it.

Not seen yet the solution, thanks

Good apetite,
Laurent
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Currently you cannot use strings for the X axis in YXCharts and you cannot have missing values in Line charts.

EDIT:
Are you looking for something like this ?



If you look at the red and blue curves you see that there are missing points.
Red line missing points at 0, 45, 270, 315, 360 and 720.
Blue line missing points at 45, 360 and 405.
In the list they are displayed as NaN.
To set missing data put the MissingDataValue at the given place.
MissingDataValue is a new property and the default value is 1000000000.
For missing points at the beginning and the end of the chart no line is drawn.
For missing points in the middle, a line is drawn between the last valid point and the next one.

This is the code I used for the example:

B4X:
For i = 0 To 720 Step 45
    ' In the case of 2 lines or more we are adding an array of values.
    ' One for each line.
    ' Make sure to create an array for each point.
    ' You cannot reuse a single array for all points.
    Private Vals(3) As Double
    Vals(0) = Rnd(-100, 101) / 300 * Ampl1 + 5
    Select i
        Case 45, 360, 405
            Vals(0) = 1000000000
    End Select       
   
    Vals(1) = Ampl2 * CosD(i) + 2
    Select i
        Case 0, 45, 270, 315, 360, 720
            Vals(1) = 1000000000
    End Select
   
    Vals(2) = Ampl3 * SinD(i) + 4
    LineChart2.AddLineMultiplePoints(i, Vals, i Mod 90 = 0)
Next

Please test the attached version 7.0.

EDIT: 2021.03.15
Removed the xChart.b4xlib file, it has been updated in the first post.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…