小吃我在本機反應中創建了一個條形圖,使用戶能夠選擇月份,并根據他們的選擇呈現圖表。然而,到目前為止我所做的只是更改 x 軸上的月份標簽。我在條形圖本身上實現用戶選擇時遇到問題。請參閱下文 -變量數據集的定義方式與官方文檔中的方式相同。必須為每條條線定義顏色。我在想,如果可以在其中包含一個 for 循環,根據標簽的數量,月份過濾器也許會起作用。我正在使用 applyDateFilter() 來調整圖表中的標簽。import {Chart,LineChart,BarChart,PieChart,ProgressChart,ContributionGraph} from 'react-native-chart-kit'import React, { Component } from 'react';import {useState, useEffect, useCallback} from 'react';import { View, Text, StyleSheet, ImageBackground, Icon, FlatList, Button, TextInput, Dimensions, SafeAreaView, Picker, Alert } from 'react-native';const initialData = [12, 19, 12, 25, 22, 10];const initialFrom = "0"const initialToMonth = "7"const months = [ { month: "Jan", value: "0" }, { month: "Feb", value: "1" }, { month: "Mar", value: "2" }, { month: "April", value: "3" }, { month: "May", value: "4" }, { month: "June", value: "5" }, ];const initialLevelsArr = [ "Jan", "Feb", "Mar", "April", "May", "June", ];const initialLabels = ["Jan", "Feb", "Mar", "April", "May", "June"];export default function FocusScreen() {const [datas, setDatas] = useState(initialData);const [from, setFrom] = useState(initialFrom);const [toMonth, setToMonth] = useState(initialToMonth);const [labels, setLabels] = useState(initialLabels);const applyDateFilter = () => { const newLabels = initialLevelsArr.slice( parseInt(from), parseInt(toMonth) + 1 ); setLabels(newLabels); console.log(labels) }const dataset = { labels: labels, datasets: [ { data: datas, colors: [ (opacity = 1) => `red`, (opacity = 1) => `blue`, (opacity = 1) => `yellow`, (opacity = 1) => `green`, (opacity = 1) => `purple`, (opacity = 1) => `orange` ] } ] }
不確定如何正確設置本月過濾器
波斯汪
2023-08-24 15:36:41