Giter Site home page Giter Site logo

Comments (12)

bklingen avatar bklingen commented on June 18, 2024 1

Thanks, seems to work just fine for the toy example:

image

And if you want to have "nice" ticks, using tickAmount works:

df <- data.frame(x=c(1, 2, 3), y=c(0, 1, 0))
apex(data=df, mapping=aes(x=x, y=y), type="line") %>%
  ax_xaxis(type="numeric", tickAmount=2)

image

Only tickAmount='dataPoints' doesn't work as advertises on the Apex help:
If you have a numeric xaxis xaxis.type = 'numeric', you can specify tickAmount: 'dataPoints' which would make the number of ticks equal to the number of dataPoints in the chart.
But I don't have a use case for it.

from apexcharter.

bklingen avatar bklingen commented on June 18, 2024 1

...and the initial example now also shows correct x-axis labels:

x <- seq(-0.3, 0.3, 0.01)
df <- data.frame(x=x, y=dnorm(x, mean=0, sd=0.1))
apex(data=df, aes(x,y), type='line') %>% 
  ax_xaxis(type='numeric', 
           max=0.3,
           range=0.6, 
           tickAmount=6, 
           labels=list(formatter=format_num(".2f"))
  )

image

from apexcharter.

bklingen avatar bklingen commented on June 18, 2024 1

There is still a small issue, though, if one wants to set a custom x-axis range: It has to do with the precision of the tick labels. Out of the box, the plot is pretty confusing:

x <- seq(-4, 4, 0.01)
df <- data.frame(x=x, y=dnorm(x))
apex(data=df, aes(x,y), type='line') %>% 
  ax_xaxis(type='numeric', 
           max=5,
           range=10, 
           tickAmount=8
           #labels=list(formatter=format_num(".2f"))
  )

image

One needs to specify the formatting of the tick labels to get a meaningful x-axis:

x <- seq(-4, 4, 0.01)
df <- data.frame(x=x, y=dnorm(x))
apex(data=df, aes(x,y), type='line') %>% 
  ax_xaxis(type='numeric', 
           max=5,
           range=10, 
           tickAmount=8,
           labels=list(formatter=format_num(".2f"))
  )

image

I.e., the -1.25 is rounded and displayed as -1, and the -2.50 is rounded and displayed as -3 in the first chart. However, if you set tickAmount=10 to begin with, everything is fine. So, overall, this is a limitation of the Apex library, not the r implementation.

from apexcharter.

pvictor avatar pvictor commented on June 18, 2024

Seems like a bug with float, it doesn't occur if we use x*100 or without tickAmount option.
I'll open an issue in Apexcharts.js repo.

Victor

from apexcharter.

artofstat avatar artofstat commented on June 18, 2024

Great, thanks. Here is a minimal reproducible example to reproduce the bug with type="numeric", where the x-axis labels are off (the x-value in the hover information is correct, though):

df <- data.frame(x=c(1, 2, 3), y=c(0, 1, 0))
apex(data=df, mapping=aes(x=x, y=y), type="line") %>%
  ax_xaxis(type="numeric")

image

from apexcharter.

bklingen avatar bklingen commented on June 18, 2024

I tried in a codepen that had version 3.4.1 of apexchart, and it did give the expected result:

image

image

from apexcharter.

pvictor avatar pvictor commented on June 18, 2024

Thanks,

Here you used categories to set x values, in apex I use numeric paired values:

"data": [
        {
          "x": 1,
          "y": 0
        },
        {
          "x": 2,
          "y": 1
        },
        {
          "x": 3,
          "y": 0
        }
      ]

The bug here seems to appear if option tickAmount is not set.

https://codepen.io/pvictor-r/pen/abBLyBX

from apexcharter.

bklingen avatar bklingen commented on June 18, 2024

Sorry if this is not the right lead (I understand very little about these things), but when you change to version 3.4.1 in your codepen (at least this is what I think I'm doing in settings), the graph does render correctly, i.e., the bug goes away. I don't know how easy it is to update to this version.

image

from apexcharter.

pvictor avatar pvictor commented on June 18, 2024

3.4.1 is actually an old version (17 Feb 2019)

Last version released is 3.23.1, and is the one used in {apexcharter} GitHub (CRAN use 3.22.2)

from apexcharter.

bklingen avatar bklingen commented on June 18, 2024

I believe the issue was fixed on Apex's gihub a few weeks ago. Any chance this will be rolled over soon, so that code like this gives correct results:

df <- data.frame(x=c(1, 2, 3), y=c(0, 1, 0))
apex(data=df, mapping=aes(x=x, y=y), type="line") %>%
  ax_xaxis(type="numeric")

Many thanks!
Bernhard

from apexcharter.

pvictor avatar pvictor commented on June 18, 2024

Yes I openned an issue (apexcharts/apexcharts.js#2249) ;)

I was waiting for an official release, however I build manually the JS bundle from Apexcharts repo so you can try.
You may experience some bugs ^^, let me know.

Victor

from apexcharter.

pvictor avatar pvictor commented on June 18, 2024

Thanks for the tests!
ApexCharts 3.26.0 has been released and included in apexcharter.
I will push to CRAN soon.

from apexcharter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.