亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不確定如何正確設置本月過濾器

不確定如何正確設置本月過濾器

波斯汪 2023-08-24 15:36:41
小吃我在本機反應中創建了一個條形圖,使用戶能夠選擇月份,并根據他們的選擇呈現圖表。然而,到目前為止我所做的只是更改 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`        ]      }    ]  }
查看完整描述

1 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

嘗試這個:


const applyDateFilter = () => {

    const newLabels = initialLevelsArr.slice(

      parseInt(from),

      parseInt(toMonth) + 1

    );

    const newDatas = initialData.slice(

      parseInt(from),

      parseInt(toMonth) + 1

    );


    setLabels(newLabels);

    setDatas(newDatas);

  }

這樣,過濾器也將應用于數據,而不僅僅是標簽。


查看完整回答
反對 回復 2023-08-24
  • 1 回答
  • 0 關注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號