Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y axis not scaling correctly #773

Open
4 tasks done
PalleRaa opened this issue Sep 11, 2024 · 10 comments
Open
4 tasks done

Y axis not scaling correctly #773

PalleRaa opened this issue Sep 11, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@PalleRaa
Copy link

Checklist

  • I updated the card to the latest version available
  • I cleared the cache of my browser
  • I verified that I'm really running the lastest version in my browser console
  • I checked if there is another issue opened with the same problem

Describe the bug
In some of my charts the data goes out-of-bounds because the y-axis is not scaling to the lowest point in the data series.

Version of the card
Version: 2.1.2

To Reproduce
This is the configuration I used:
Example #1

type: custom:apexcharts-card
graph_span: 48h
header:
  show: true
  title: Kælder
  show_states: true
series:
  - entity: sensor.basement_wall_sensor_humidity
    type: line
    unit: '%'
    show:
      name_in_header: false

Example #2

type: custom:apexcharts-card
graph_span: 48h
header:
  show: true
  title: Toilet
  show_states: true
series:
  - entity: sensor.toilet_wall_sensor_temperature
    type: line
    unit: °C
    show:
      name_in_header: false

Screenshots
Example #1
image
image

Example #2
image
image

Expected behavior
I expect the y-axis to scale correctly according to highest and lowest value of data

Desktop (please complete the following information):
Version 128.0.6613.85 (Official Build) (64-bit)

Smartphone (please complete the following information):

  • Device: iPhone12]
  • OS: iOS 17.6.1
  • Browser Stock Safari

Additional context
Add any other context about the problem here.

@PalleRaa PalleRaa added the bug Something isn't working label Sep 11, 2024
@gcoan
Copy link

gcoan commented Oct 18, 2024

I think I have the same problem, the y-axis not being auto-scaled to the data series and values are getting clipped off the top and bottom.

For some reason, the y-axis is scaling from 15 to 40 despite min and max not being set (so default to auto). Setting them explicitly to min/max auto has the same result:
IMG_1452

If I manually add a min and max the chart correctly displays all the data, e.g. min -5, max 45:
IMG_1453

Chart config:

type: custom:apexcharts-card
apex_config:
  chart:
    height: 300px
header:
  title: Agile Price Forecast
  show: true
  show_states: true
  colorize_states: true
graph_span: 5d
now:
  show: true
  label: Now
yaxis:
  - id: price (pence)
    decimals: 0
    min: -5
    max: 45
    apex_config:
      tickAmount: 10
stacked: false
span:
  start: day
series:
  - entity: sensor.octopus_energy_electricity_XXXX_XXXX_current_rate
    name: Actual Agile Import (current rate)
    transform: return x * 100;
    show:
      in_chart: false
    unit: p/kWh
  - entity: >-
      event.octopus_energy_electricity_XXXX_XXXX_current_day_rates
    yaxis_id: price
    name: Actual Import (today)
    color: grey
    opacity: 1
    stroke_width: 2
    extend_to: now
    type: column
    unit: p/kWh
    data_generator: |
      return entity.attributes.rates.map((entry) => {
         return [new Date(entry.start), entry.value_inc_vat*100];
       });     
    offset: "-15min"
    show:
      in_header: false
      legend_value: false
      offset_in_name: false
  - entity: event.octopus_energy_electricity_XXXX_XXXX_next_day_rates
    yaxis_id: price
    name: Actual Import (tomorrow)
    color: grey
    opacity: 0.3
    stroke_width: 2
    type: column
    unit: p/kWh
    data_generator: |
      return entity.attributes.rates.map((entry) => {
         return [new Date(entry.start), entry.value_inc_vat*100];
       });     
    offset: "-15min"
    show:
      in_header: false
      legend_value: false
      offset_in_name: false
  - entity: sensor.octopus_agile_predict
    yaxis_id: price
    name: Predicted Agile
    color: red
    opacity: 1
    stroke_width: 1
    extend_to: now
    unit: p/kWh
    data_generator: |
      return entity.attributes.prices.map((entry) => {
         return [new Date(entry.date_time), entry.agile_pred];
       });     
    offset: "-15min"
    show:
      in_header: false
      legend_value: false
      offset_in_name: false

@PalleRaa
Copy link
Author

Could be related to #780

@gcoan
Copy link

gcoan commented Oct 22, 2024

Could be related to #780

Thank you, my chart issue is #780. I had looked at that issue and thought that it wasn't, but now I have pasted the YAML for my chart above, I can see that I am using in_chart: false for one of my series

@stormdilley
Copy link

I have a similar issue, which I reported, but it was just closed without any comment or explanation.
max: auto Used to work and still does in earlier versions, but in this version, only an actual value works, but the value max, I just end up with a value of 10 irrespective of what it should be. Actually to go further, if you set max: (anything other than a number) you get the value 10).
I have tried this on a new build of Home Assistant still no joy, the last version that works correctly is v2.0.4

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Dec 24, 2024
@gcoan
Copy link

gcoan commented Dec 24, 2024

this is still an issue

@stormdilley
Copy link

stormdilley commented Dec 24, 2024 via email

@github-actions github-actions bot removed the Stale label Dec 25, 2024
@weado
Copy link

weado commented Jan 3, 2025

Hello, I have the same issue.
image
But if I put yaxis max and min :
image

@vidarak
Copy link

vidarak commented Jan 6, 2025

I think I have the same problem, the y-axis not being auto-scaled to the data series and values are getting clipped off the top and bottom.

For some reason, the y-axis is scaling from 15 to 40 despite min and max not being set (so default to auto). Setting them explicitly to min/max auto has the same result: IMG_1452

If I manually add a min and max the chart correctly displays all the data, e.g. min -5, max 45: IMG_1453

Chart config:

type: custom:apexcharts-card
apex_config:
  chart:
    height: 300px
header:
  title: Agile Price Forecast
  show: true
  show_states: true
  colorize_states: true
graph_span: 5d
now:
  show: true
  label: Now
yaxis:
  - id: price (pence)
    decimals: 0
    min: -5
    max: 45
    apex_config:
      tickAmount: 10
stacked: false
span:
  start: day
series:
  - entity: sensor.octopus_energy_electricity_XXXX_XXXX_current_rate
    name: Actual Agile Import (current rate)
    transform: return x * 100;
    show:
      in_chart: false
    unit: p/kWh
  - entity: >-
      event.octopus_energy_electricity_XXXX_XXXX_current_day_rates
    yaxis_id: price
    name: Actual Import (today)
    color: grey
    opacity: 1
    stroke_width: 2
    extend_to: now
    type: column
    unit: p/kWh
    data_generator: |
      return entity.attributes.rates.map((entry) => {
         return [new Date(entry.start), entry.value_inc_vat*100];
       });     
    offset: "-15min"
    show:
      in_header: false
      legend_value: false
      offset_in_name: false
  - entity: event.octopus_energy_electricity_XXXX_XXXX_next_day_rates
    yaxis_id: price
    name: Actual Import (tomorrow)
    color: grey
    opacity: 0.3
    stroke_width: 2
    type: column
    unit: p/kWh
    data_generator: |
      return entity.attributes.rates.map((entry) => {
         return [new Date(entry.start), entry.value_inc_vat*100];
       });     
    offset: "-15min"
    show:
      in_header: false
      legend_value: false
      offset_in_name: false
  - entity: sensor.octopus_agile_predict
    yaxis_id: price
    name: Predicted Agile
    color: red
    opacity: 1
    stroke_width: 1
    extend_to: now
    unit: p/kWh
    data_generator: |
      return entity.attributes.prices.map((entry) => {
         return [new Date(entry.date_time), entry.agile_pred];
       });     
    offset: "-15min"
    show:
      in_header: false
      legend_value: false
      offset_in_name: false

I notice you have multiple data series mapped to the same yaxis, so you might be running into same issue as me. I just found a workaround for this:
#617 (comment)

@stormdilley
Copy link

As already mentioned I spent 2 days trying to get this to work and I still have the new Apex version on my test HA Pi. I have looked at #617 (comment) and that doesn't work for me.

The nearest that I can get this to work is as follows, but 'forceNiceScale' doesn't work the wy this configured and I have given up with max and min values.

image

type: custom:config-template-card
entities:
  - entity: sensor.my_dayhours
  - entity: sensor.my_offset
variables:
  offs: states['sensor.my_offset'].state+'h'
  span: states['sensor.my_dayhours'].state+'h'
card:
  type: custom:apexcharts-card
  graph_span: ${span}
  span:
    start: day
    offset: ${'+'+offs }
  header:
    show: true
    show_states: true
    title: ENERGY TODAY
  apex_config:
    chart:
      background: lightcyan
      fontFamily: Arial
      foreColor: darkblue
      height: 350
    legend:
      show: true
      fontSize: 15
      fontFamily: Arial
      fontWeight: 400
      labels:
        useSeriesColors: true
  yaxis:
    - id: Energy
      opposite: true
      decimals: 0
      apex_config:
        axisBorder:
          show: true
          color: darkblue
        axisTicks:
          show: true
          color: darkblue
        title:
          text: Energy
          style:
            color: greenyellow
            fontSize: 16
            fontWeight: 600
            fontFamily: Arial
    - id: Power
      opposite: false
      decimals: 0
      apex_config:
        axisBorder:
          show: true
          color: darkblue
        axisTicks:
          show: true
          color: darkblue
        title:
          text: Power
          style:
            color: forestgreen
            fontSize: 16
            fontWeight: 600
            fontFamily: Arial
  all_series_config:
    type: area
    extend_to: false
    float_precision: 0
  series:
    - color: greenyellow
      entity: sensor.pv_energy
      name: Energy
      yaxis_id: Energy
      type: area
      stroke_width: 2
      unit: Wh
      show:
        name_in_header: true
        legend_value: false
        extremas: false
      group_by:
        func: max
        duration: 5 mins
    - color: forestgreen
      entity: sensor.pv_power
      name: Power
      yaxis_id: Power
      type: line
      stroke_width: 2
      unit: Wh
      show:
        name_in_header: true
        legend_value: false
        extremas: true
      group_by:
        func: max
        duration: 5 mins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants