Compute daily CO2 emissions from electricity consumption

Hi,
I currently get my local grid CO2 intensity from the electricitymap integration: Electricity Maps - Home Assistant.
I also have a cumulative_energy sensor that gives the total energy consumption (in kWh) of my home since day 0.

I’d like to make a bar chart that displays my daily CO2 emissions, but I don’t know how to achieve this.

I tried this

  - name: "Daily Energy Consumption"
    unique_id: "daily_energy_consumption"
    unit_of_measurement: "kWh"
    state: >
      {% set current =  states('sensor.cumulative_energy') | float %}
      {% set previous = state_attr('sensor.cumulative_energy', 'last_changed') %}
      {% if previous %}
        {% set previous_value = previous | float %}
        {{ current - previous_value }}
      {% else %}
        0
      {% endif %}

  - name: "Daily gCO2eq"
    unique_id: "daily_gco2eq"
    unit_of_measurement: "gCO2eq"
    state: >
      {% set daily_energy = states('sensor.daily_energy_consumption') | float %}
      {% set gco2eq_per_kwh = states('sensor.electricity_maps_co2_intensity') | float %}
      {{ daily_energy * gco2eq_per_kwh }}

and tried to use apexcharts-card to display this, but without sucess.

type: custom:apexcharts-card
graph_span: 7d
header:
  show: true
  title: Daily CO2 Emissions
series:
  - entity: sensor.daily_gco2eq
    type: column
    name: CO2 Emissions
    data_generator: |
      return entity.history.map((entry) => {
        return [new Date(entry.last_changed).getTime(), entry.state];
      });
    show:
      legend_value: true
apex_config:
  chart:
    height: 350px
  yaxis:
    title:
      text: "gCO2eq"
  xaxis:
    title:
      text: "Date"
    type: datetime
    labels:
      format: "dd/MM"

Any idea how I could plot this chart ?

Thanks !