Apex Charts vehicule contract visualisation

Hi everyone,

I’m trying to have a graph that displays the current odometer value together with a straight line that represent the supposed mileage. One of our vehicule is a rent contract so we must monitor where we are from the contract end.

I did the graph this way:

...
series:
  - entity: sensor.golf_8_ehybrid_odometer
    extend_to: false
    stroke_width: 3
    statistics:
      type: state
  - entity: sensor.golf_odometer_targets
    curve: straight
    stroke_width: 2
    data_generator: |
      return entity.attributes.values.map((odo, index) => {
        return [entity.attributes.timestamp[index], odo];
      });

And I have a custom template sensor that returns the timestamp and the mileage for the start and end point.

- sensor:
    - name: Golf Odometer targets
      unique_id: golf_target_odo
      unit_of_measurement: km
      state: >
        {{ states('sensor.golf_8_ehybrid_odometer') }}
      attributes:
        values: "{{ [0, 45000] }}"
        timestamp: "{{ [1634248800000, 1731625200000] }}"

Current result is this:

Capture d’écran 2024-03-03 à 15.02.55

I’m curious if you guys would have done this in another way.

And I’m looking for a solution to display the delta between the two lines (basically meaning by how much we are ahead or not of the contract).