Nutrition breakdown
Calories by nutrient in a ring, and grams against a goal. Good for diet apps, meal plans and nutrition advice.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'macros',
goal: 2200,
data: [
{ name: 'Protein', grams: 106, goal: 120 },
{ name: 'Carbohydrates', grams: 219, goal: 250 },
{ name: 'Fat', grams: 56, goal: 70 },
],
};
export default function Example() {
return <Chart spec={spec} style={{ height: 340 }} />;
}Or import this chart alone: what each import weighs.
Options
Beside the fields shared by every chart (title, format, heading, export…), type macros takes:
/** Calories and macronutrients: the energy share of each, and grams against a goal. */
interface MacrosSpec extends Base {
type: 'macros';
/** Protein, carbohydrates, fat… `kcal` by gram: 4, or 9 for a name with "fat", 7 for "alcohol". */
data: { name: string; grams: number; goal?: number; kcal?: number; color?: string }[];
/** Calories planned for the day. */
goal?: number;
}Style it
- Colours:
theme.palette,chart.setColor(name, colour), or--nervure-palettein your CSS. More - Marks:
[data-series="name"], parts:[data-part="axes"],legend,series. What you change is kept in exports. - Movement:
animation: falsedraws at once. More - Files:
chart.download('png'),svg,csv. More