仪表盘 React 组件
Framework7 配有仪表盘组件。它产生美观的完全响应式 SVG 仪表盘。
仪表盘组件
包含以下组件
- 仪表盘
仪表盘属性
| 属性 | 类型 | 默认 | 说明 | 
|---|---|---|---|
| id | string | 仪表盘元素 ID 属性 | |
| type | string | circle | 仪表盘类型。可以是 circle或semicircle | 
| value | number | 0 | 仪表盘值/百分比。必须是 0和1之间的数字 | 
| size | number | 200 | 生成的 SVG 图像大小(以像素为单位) | 
| bgColor | string | transparent | 仪表盘背景颜色。可以为任何有效的颜色字符串,例如: #ff00ff、rgb(0,0,255)等。 | 
| borderBgColor | string | #eeeeee | 主边框/笔划背景颜色 | 
| borderColor | string | #000000 | 主边框/笔划颜色 | 
| borderWidth | string | 10 | 主边框/笔划宽度 | 
| valueText | string | null | 仪表盘值文本(仪表盘中心的大文本) | 
| valueTextColor | string | #000000 | 值文本颜色 | 
| valueFontSize | string | 31 | 值文本字体大小 | 
| valueFontWeight | string | 500 | 值文本字体粗细 | 
| labelText | string | null | 仪表盘附加标签文本 | 
| labelTextColor | string | #888888 | 标签文本颜色 | 
| labelFontSize | string | 14 | 标签文本字体大小 | 
| labelFontWeight | string | 400 | 标签文本字体粗细 | 
示例
gauge.jsx
import React, { useState } from 'react';
import { Navbar, Page, BlockTitle, Block, Segmented, Button, Gauge } from 'framework7-react';
export default () => {
  const [gaugeValue, setGaugeValue] = useState(0.5);
  return (
    <Page>
      <Navbar title="Gauge"></Navbar>
      <Block strongIos outlineIos>
        <p>
          Framework7 comes with Gauge component. It produces nice looking fully responsive SVG
          gauges.
        </p>
      </Block>
      <Block strongIos outlineIos className="text-align-center">
        <Gauge
          type="circle"
          value={gaugeValue}
          size={250}
          borderColor="#2196f3"
          borderWidth={10}
          valueText={`${gaugeValue * 100}%`}
          valueFontSize={41}
          valueTextColor="#2196f3"
          labelText="amount of something"
        />
        <Segmented tag="p" raised>
          <Button active={gaugeValue === 0} onClick={() => setGaugeValue(0)}>
            0%
          </Button>
          <Button active={gaugeValue === 0.25} onClick={() => setGaugeValue(0.25)}>
            25%
          </Button>
          <Button active={gaugeValue === 0.5} onClick={() => setGaugeValue(0.5)}>
            50%
          </Button>
          <Button active={gaugeValue === 0.75} onClick={() => setGaugeValue(0.75)}>
            75%
          </Button>
          <Button active={gaugeValue === 1} onClick={() => setGaugeValue(1)}>
            100%
          </Button>
        </Segmented>
      </Block>
      <BlockTitle>Circle Gauges</BlockTitle>
      <Block strongIos outlineIos>
        <div className="grid grid-cols-2 grid-gap">
          <div className="text-align-center">
            <Gauge
              type="circle"
              value={0.44}
              valueText="44%"
              valueTextColor="#ff9800"
              borderColor="#ff9800"
            />
          </div>
          <div className="text-align-center">
            <Gauge
              type="circle"
              value={0.12}
              valueText="$120"
              valueTextColor="#4caf50"
              borderColor="#4caf50"
              labelText="of $1000 budget"
              labelTextColor="#f44336"
              labelFontWeight={700}
            />
          </div>
        </div>
      </Block>
      <BlockTitle>Semicircle Gauges</BlockTitle>
      <Block strongIos outlineIos>
        <div className="grid grid-cols-2 grid-gap">
          <div className="text-align-center">
            <Gauge
              type="semicircle"
              value={0.3}
              valueText="30%"
              valueTextColor="#f44336"
              borderColor="#f44336"
            />
          </div>
          <div className="text-align-center">
            <Gauge
              type="semicircle"
              value={0.5}
              valueText="30kg"
              valueTextColor="#e91e63"
              borderColor="#e91e63"
              labelText="of 60kg total"
              labelTextColor="#333"
            />
          </div>
        </div>
      </Block>
      <BlockTitle>Customization</BlockTitle>
      <Block strongIos outlineIos>
        <div className="grid grid-cols-2 grid-gap">
          <div className="text-align-center">
            <Gauge
              type="circle"
              value={0.35}
              valueText="35%"
              valueTextColor="#4caf50"
              valueFontSize={51}
              valueFontWeight={700}
              borderWidth={20}
              borderColor="#4caf50"
              borderBgColor="#ffeb3b"
              bgColor="#ffeb3b"
            />
          </div>
          <div className="text-align-center">
            <Gauge
              type="circle"
              value={0.67}
              valueText="$670"
              valueTextColor="#000"
              borderColor="#ff9800"
              labelText="of $1000 spent"
              labelTextColor="#4caf50"
              labelFontWeight={800}
              labelFontSize={12}
              borderWidth={30}
            />
          </div>
        </div>
        <br />
        <div className="grid grid-cols-2 grid-gap">
          <div className="text-align-center">
            <Gauge
              type="semicircle"
              value={0.5}
              valueText="50%"
              valueTextColor="#ffeb3b"
              valueFontSize={41}
              valueFontWeight={700}
              borderWidth={10}
              borderColor="#ffeb3b"
              borderBgColor="transparent"
            />
          </div>
          <div className="text-align-center">
            <Gauge
              type="semicircle"
              value={0.77}
              borderColor="#ff9800"
              labelText="$770 spent so far"
              labelTextColor="#ff9800"
              labelFontWeight={800}
              labelFontSize={12}
              borderWidth={10}
            />
          </div>
        </div>
      </Block>
    </Page>
  );
};


