useEnergySummary
This hook is used to transform the raw measurements data into useful statistics that can be displayed inside the EnergySummary component.
Basic Usage
import { useEnergySummary } from '@krakentech/coral-charts';
const {
percentageDifference,
energyTypeLabel,
electricity,
gas,
weekBeforeCostTotalFormatted,
lastWeekCostTotalFormatted,
} = useEnergySummary({
data,
energyType: 'dual',
loading: false,
error: false,
currency: 'GBP',
locale: 'en',
});The returned values can then be used to display the relevant statistics inside your component. Please see the EnergySummary component for a full example.
Full API
Arguments
| Name | Description | type | Default value | Required |
|---|---|---|---|---|
data | The initial data provided by the consumer from the GraphQL query | EnergySummaryDataType | undefined | true |
energyType | The energy type(s) this chart should display | electricity, gas, dual | undefined | true |
loading | The loading state from the GraphQL query | boolean | undefined | true |
error | The error state from the GraphQL query | unknown | undefined | true |
currency | The local 3-digit currency code | GBP, USD, EUR, JPY, AUD, NZD, string | undefined | true |
locale | The local 2-digit locale code | en, us, fr, de, es, it, ja, au, nz | undefined | true |
Return
| Name | Description | type |
|---|---|---|
percentageDifference | The total percentage difference between the energy consumed in the week before, compared to last week | number |
kwhDifference | The total kWh difference between the energy consumed in the week before, compared to last week | number |
energyTypeLabel | The human-readable label that will be displayed when talking about which energy type they are viewing | 'gas', 'electricity', 'energy' |
weekBeforeCostTotalFormatted | The total week before cost formatted based on your currency and locale | string |
lastWeekCostTotalFormatted | Last week’s total cost formatted based on your currency and locale | string |
[energy type].weekBeforeData.costValue | The cost value of the week before | number |
[energy type].weekBeforeData.consumptionValue | The consumption value of the week before | number |
[energy type].weekBeforeData.isCostAvailable | Whether the cost data is available for the week before | boolean |
[energy type].weekBeforeData.costValueFormatted | The formatted cost value of the week before based on your currency and locale | string |
[energy type].weekBeforeData.consumptionValueFormatted | The formatted consumption value of the week before based on your locale | string |
[energy type].weekBeforeData.costDifferenceFormatted | The formatted cost difference between the week before and last week based on your currency and locale | string |
[energy type].lastWeekData | The same structure as weekBeforeData, but for last week | TimePeriodDataType |
[energy type].costDifferenceFormatted | The formatted cost difference between the week before and last week based on your currency and locale | string |
Last updated on