B4J Library jCharts

Discussion in 'B4J Libraries & Classes' started by Informatix, Oct 13, 2016.

  1. Vanja

    Vanja New Member



    I wonder if you can tell me how did you manage to make Mouse Moved event with Time as we can see it on picture in post #10? It has to be a number on X axis. Did you convert time to number or did u used some other method?
     
  2. Lahksman

    Lahksman Active Member Licensed User

    I have a linechart with 5 series and I would like to give each one its own color.
    I know it can be done by css but the problem is that the users can choose which series they want to display in runtime.

    So the order and number of series isn't always the same. Is there any way i can solve this?
    upload_2017-7-26_16-7-12.png upload_2017-7-26_16-10-28.png
     
  3. Informatix

    Informatix Expert Licensed User

    Code:
    Dim FirstLineStyle As Map = LineChart.GetChildStyleMap(".default-color0.chart-series-line")
    FirstLineStyle.Put(
    "-fx-stroke""#your_color")
    LineChart.SetChildStyleMap(
    ".default-color0.chart-series-line", FirstLineStyle)
    Dim SecondLineStyle As Map = LineChart.GetChildStyleMap(".default-color1.chart-series-line")
    SecondLineStyle.Put(
    "-fx-stroke""#your_color")
    LineChart.SetChildStyleMap(
    ".default-color1.chart-series-line", SecondLineStyle)
    etc.
     
    Lahksman and raphaelcno like this.
  4. Lahksman

    Lahksman Active Member Licensed User

    Got the line colors working. Each series has its own color.
    Now facing the next challenge. Somehow the legend isn't following the line colors.

    Right now I use this code to set the line and symbol style.
    Code:
    Dim LineStyle As Map = DockNode3LineChart.GetChildStyleMap(".default-color" & (seriesNumber) & ".chart-series-line")
        
    Dim SymbolStyle As Map = DockNode3LineChart.GetChildStyleMap(".default-color" & (seriesNumber) & ".chart-line-symbol")
        
    Select series
            
    Case "Average": LineStyle.Put("-fx-stroke""red")
                SymbolStyle.Put(
    "-fx-background-color""red, white")
                ...
        
    End Select
        DockNode3LineChart.SetChildStyleMap(
    ".default-color" & (seriesNumber) & ".chart-series-line", LineStyle)
        DockNode3LineChart.SetChildStyleMap2(
    ".default-color" & (seriesNumber) & ".chart-line-symbol", SymbolStyle)
    I've been googling this but haven't been able to resolve it. Is there a separate css for the legend symbol colors?
     
  5. Informatix

    Informatix Expert Licensed User

    Only after the form is shown:
    Code:
    Dim StyleMap As Map = LineChart.GetChildStyleMap(".default-color0.chart-legend-item-symbol")
    If StyleMap.IsInitialized Then
         StyleMap.Put(
    "-fx-background-color""#your_color")
         LineChart.SetChildStyleMap(
    ".default-color0.chart-legend-item-symbol", StyleMap)
    End If
     
    Lahksman likes this.
  6. Pravin Shah

    Pravin Shah Member Licensed User

    Dear @Informatix, Very good charting library for B4J.

    I am working on Stock market related application using B4J where I need to show stock prices using candlestick chart. I could not find the candlestick option in the above library so is it possible to draw candlestick charts using above library?
    I will have the stock data in the format of Open, High, Low, Close and Volume.
     
  7. Lahksman

    Lahksman Active Member Licensed User

    I don't think that javafx.scene.chart (on which this lib is based) contains candlestick charts.
     
    Pravin Shah likes this.
  8. Pravin Shah

    Pravin Shah Member Licensed User

    Thanks @Lahksman for quick reply. Do you or anyone know any Chart library supporting candlestick charts?

    I tried searching the forum but could not find any library for B4J. There are some libraries available for B4A supporting candlestick but not for B4J. I would appreciate if anyone could point me to this library
     
  9. Lahksman

    Lahksman Active Member Licensed User

    You could take a look at google charts.
    See this post for more info.

    EDIT: If you have any more questions about this, it's best to start a new topic. Otherwise we would be hijacking this thread.
     
    Pravin Shah likes this.
  10. Informatix

    Informatix Expert Licensed User

    Two ideas:
    - using a StackedBarChart with two series where the first one is invisible (so you have the candle body for Open/Close);
    - drawing a line at each position with the Plot event for High/Low (see the ChartWithjGraphiblib demo).
    or drawing everything with the Plot event.
     
    Pravin Shah likes this.
  11. Pravin Shah

    Pravin Shah Member Licensed User

    Thank you @Informatix, I will give it a try. Appreciate your help.
     
  12. Pravin Shah

    Pravin Shah Member Licensed User

    Thanks @Lahksman for the link. The google charts are available for web, I am looking for desktop application.
     
  13. tufanv

    tufanv Expert Licensed User

    Hello,
    I have 3 questions
    1) solution found to q1

    2) is it possible to hide the values of x axis as seen in the pic as 0 , 2.5 , 5.0 .... etc




    3)I am trying to change the default color of red (or pink ) of area chart , I chedked post 11 and trying to use :

    Code:
    Dim style As Map = AreaChart.GetChildStyleMap(".default-color1.chart-symbol")
        style.Put(
    "-fx-background-color""red" )
        AreaChart.SetChildStyleMap(
    ".default-color1.chart-symbol", style)
    I am not sure if my code is correct but I always get map not nitialized error even if i initialize it first. Can you lease help me change the color of the area that is under the line.

    Thanks
     
    Last edited: Jul 31, 2017
  14. Informatix

    Informatix Expert Licensed User

    2)
    By setting properly TickUnit, LowerBound and UpperBound (for a NumberAxis), you should get the expected result.

    3)
    ".default-color1.chart-symbol" is obviously an invalid style name.
    Code:
    Dim FirstAreaStyle As Map = AreaChart.GetChildStyleMap(".default-color0.chart-series-area-fill")
    FirstAreaStyle.Put(
    "-fx-fill""#your_color")
    AreaChart.SetChildStyleMap(
    ".default-color0.chart-series-area-fill", FirstAreaStyle)
     
  15. tufanv

    tufanv Expert Licensed User

    Hi Informatix ,

    Thanks very much for the answer. An interesting thing happens when i use the code snippet you put. The fill is happening for a second for my selected color , than changes back to red-pink again.

    edit: by thw way for the x axis I want to show dates but I cant use a date format there I always get java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number , Is there a way to show date for the x axis instead of numbers ? , sorry I am trying to understand by reading past posts but cant figure it out , I think it is possible for line chart for example but not for area chart)
     
    Last edited: Aug 1, 2017
  16. Informatix

    Informatix Expert Licensed User

    There's probably something in your code that restores the original color or negates the change. Try my code in the demo. You won't get this issue.

    In the demo, if you replace XAxisSAC by XAxisBC, which is a CategoryAxis, and Series by Series1 and Series2 for the data, you will display months on the XAxis.
    The only thing that is not possible is to have a CategoryAxis for the Y axis (pretty logical for a stacked chart).
     
    tufanv likes this.
  17. tufanv

    tufanv Expert Licensed User

    Thanks very much for your help ! I will do as you say.
     
  18. tufanv

    tufanv Expert Licensed User

    Everything works perfect now , my problem is just , If I add the areachart with designer, I cant set lower bounds and upperbounds as xaxissac and yaxissac is not anymore used by the code , how can i set that when I add it by designer ?

    ( because i dont use anymore this code when adding with designer :

    Code:
    XAxisSAC.Initialize("")
        YAxisSAC.Initialize(
    "")

        AreaChart.Initialize(XAxisSAC, YAxisSAC, 
    "AC")
    these also dont work:

    Code:
    YAxisSAC.AutoRanging=False
                YAxisSAC.LowerBound=listegrafik.Get(
    0)
                YAxisSAC.LowerBound=YAxisSAC.LowerBound
                YAxisSAC.UpperBound=listegrafik.Get(listegrafik.Size-
    1)
                YAxisSAC.UpperBound=YAxisSAC.UpperBound
    and i cant reach the axis controls when added with designer.
     
  19. Informatix

    Informatix Expert Licensed User

    You can get them with the XAxis and YAxis properties of your chart (e.g. YAxisSAC = AreaChart.YAxis).
     
    tufanv likes this.
Loading...