Chart.js 4.36 KB
/**
 * Created by yzdd on 2018/3/17.
 */
import React, {Component} from 'react';
import {
  View,
  Text,
  StyleSheet,
  Image,
  TextInput,
  ScrollView
} from 'react-native';
import {publicStyle, width} from "../utils/publiscStyle";
import SegmentedControlTab from 'react-native-segmented-control-tab'
import PieChart from "react-native-pie-chart";

const styles = StyleSheet.create({
  tabView: {
    width,
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
    marginTop: 17
  },
  titleView: {
    width,
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
    marginTop: 28
  },
  font1: {
    fontSize: 18,
    color: "#000000"
  },
  chartView: {
    width,
    height: 191,
    alignItems: 'center',
    justifyContent: "center",
    marginTop: 19
  },
  font2: {
    fontSize: 14,
    color: "#808080",
  },
  font3: {
    fontSize: 12,
    color: "#000000"
  },
  font4: {
    fontSize: 18,
    color: "#000000"
  },
  colorView: {
    flexDirection: 'row',
    flexWrap: "wrap",
    marginTop: 25,
    marginBottom: 25
  },
  colorItem: {
    width: width / 2,
    height: 104 / 4,
    flexDirection: 'row',
    alignItems: 'center',
    paddingLeft: 49
  },
  font5: {
    fontSize: 12,
    color: "#666666",
    marginRight: 30
  },
  font6: {
    fontSize: 12,
    color: "#666666"
  },
  itemTitleView: {
    width,
    height: 30,
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: "#ececf1",
    paddingLeft: 15
  },
  font7: {
    fontSize: 14,
    color: "#666666"
  },
  monthItem: {
    width,
    height: 60,
    flexDirection: 'row',
    alignItems: "center",
    justifyContent: "space-between",
    paddingLeft: 15,
    paddingRight: 15
  },
  font8: {
    fontSize: 16,
    color: "#000000"
  }
});

const chart_wh = 191;
const series = [35, 35, 25, 25, 0, 0, 0]
const sliceColor = [
  '#ff9900',
  '#ee5e53',
  '#52c26e',
  '#3399ff',
  '#cf8af6',
  "#5c39ee",
  "#799bf2"
];

export default class Chart extends Component {
  static navigationOptions = ({navigation}) => {
    return {
      title: "报表"
    }
  };

  constructor() {
    super()
    this.state = {
      selectedIndex: 0,
    };
  }

  handleIndexChange = (index) => {
    this.setState({
      ...this.state,
      selectedIndex: index,
    });
  }

  render() {
    return (
      <ScrollView>
        <View style={[publicStyle.container, {backgroundColor: "#FFFFFF"}]}>
          <View style={styles.tabView}>
            <SegmentedControlTab
              tabsContainerStyle={{width: 152, height: 30}}
              values={['个人', '团队']}
              selectedIndex={this.state.selectedIndex}
              onTabPress={this.handleIndexChange}
            />
          </View>
          <View style={styles.titleView}>
            <Text style={styles.font1}>12个月</Text>
          </View>
          <View style={styles.chartView}>
            <PieChart
              style={{position: "absolute", left: (width - 191) / 2, top: 0}}
              chart_wh={chart_wh}
              series={series}
              sliceColor={sliceColor}
              doughnut={true}
              coverRadius={0.75}
              coverFill={'#FFF'}
            />
            <Text style={styles.font2}>共计</Text>
            <Text style={styles.font3}>¥
              <Text style={styles.font4}>360.00</Text>
            </Text>
          </View>
        </View>
        <View style={styles.colorView}>
          {
            sliceColor.map((v, i) => {
              return (
                <View
                  style={styles.colorItem}
                  key={i}
                >
                  <View style={{width: 10, height: 10, borderRadius: 10, backgroundColor: `${v}`, marginRight: 8}}/>
                  <Text style={styles.font5}>餐饮</Text>
                  <Text style={styles.font6}>{series[i] + "%"}</Text>
                </View>
              )
            })
          }
        </View>
        <View style={styles.itemTitleView}>
          <Text style={styles.font7}>月份统计{" "}()</Text>
        </View>
        {
          [1, 2, 3, 4, 5].map((v, i) => {
            return (
              <View style={styles.monthItem} key={i}>
                <Text style={styles.font8}>2016-06</Text>
                <Text style={styles.font8}>30.00</Text>
              </View>
            )
          })
        }
      </ScrollView>
    );
  }
}