Diabetes Diary Chart

A working demo of the combined progress chart from the requirements: glucose, carbohydrates, basal and bolus insulin on one time axis with three independent Y-axes. Built with Apache ECharts, the same library the app can use through @wuba/react-native-echarts. The data is generated sample data, not a real patient.

Period

Tap or hover a point or bar for details. Pinch, scroll or drag to zoom into a time window; every reading stays on the chart even when the axis shows fewer labels. Shaded band: 70–180 mg/dL target range.

What this demo covers

  • Glucose as a solid line with circles, carbs as a dashed line with squares, basal and bolus as two bar styles
  • BE shown on each meal point, and in the tooltip next to the selected carb unit
  • Three Y-axes, each scaled on its own: glucose left, carbs right, insulin outer right
  • Unit switching with the diary's factors (18.02, 15, 10, 12 g) and decimals from the units table
  • Carb points only where a meal was logged, with no zero values in between
  • 1, 3, 7, 14 and 21 day ranges; hour labels for one day, date labels for longer, thinned when crowded
  • Every event placed at its real timestamp, so meal → bolus → glucose response reads left to right
  • Tooltip with date and time, parameter, value and unit, for the events at that moment only

Using it in React Native same config

Install echarts, @wuba/react-native-echarts and a renderer (@shopify/react-native-skia or react-native-svg). The buildOption() function on this page can be moved into the app unchanged.

import * as echarts from 'echarts/core';
import {LineChart, BarChart} from 'echarts/charts';
import {GridComponent, TooltipComponent, LegendComponent,
  DataZoomComponent, MarkAreaComponent} from 'echarts/components';
import {SkiaRenderer, SkiaChart} from '@wuba/react-native-echarts';

echarts.use([SkiaRenderer, LineChart, BarChart, GridComponent,
  TooltipComponent, LegendComponent, DataZoomComponent, MarkAreaComponent]);

function DiaryChart({option, width, height}) {
  const ref = useRef(null);
  useEffect(() => {
    const chart = echarts.init(ref.current, 'light',
      {renderer: 'skia', width, height});
    chart.setOption(option);
    return () => chart.dispose();
  }, [option, width, height]);
  return <SkiaChart ref={ref} />;
}