Closed 9thCosmos closed 2 years ago
"react-native-echarts-pro": "1.8.1", "react-native": "0.64.1",
Formatter worked when chart show firstly, but after updated chart data, formatter doesn't work. I tried "show source", it also doesn't work.
Remove RNEChartsPro from render function and then add it back, trigger the hot reloading, then maybe it will work. OR go back to the previous page and then back to this page maybe work.
I'm sorry I couldn't reproduce it.
But, you can try my test:
import React, { useRef } from "react";
import { View, Button } from "react-native";
import RNEChartsPro from "react-native-echarts-pro";
export default function ChartsComponent() {
const echartsRef = new useRef(null);
function change() {
echartsRef.current.setNewOption({
xAxis: {
type: "category",
data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
},
yAxis: {
type: "value",
},
series: [
{
data: [180, 140, 164, 218, 135, 147, 260],
type: "line",
},
],
});
}
function getChartOption(yAxisData) {
let xAxisData = [];
for (let i = 0; i < 24; i++) {
xAxisData.push(i + "");
}
let xAxis = {
type: "category",
nameTextStyle: {
color: "#999999",
fontWeight: "400",
fontSize: 9,
lineHeight: 15,
},
axisLabel: {
showMaxLabel: true,
interval: 3,
},
axisPointer: {
show: true,
type: "line",
lineStyle: {
color: "#BCBCBC",
width: 1,
type: "solid",
},
label: {
show: false,
},
},
data: xAxisData,
};
let yAxis = {
type: "value",
position: "right",
};
let tooltip = {
trigger: "axis",
position: "right",
backgroundColor: "#4D4D4D",
borderWidth: 0,
formatter: function (params) {
("show source");
return "<span style='color:#ffffff80'>" + params[0].value;
},
};
return {
xAxis: {
type: "category",
data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
},
yAxis: {
type: "value",
},
tooltip: tooltip,
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: "line",
},
],
};
}
return (
<View
style={{
backgroundColor: "#fff",
height: 350,
paddingTop: 25,
}}>
<RNEChartsPro
ref={echartsRef}
option={getChartOption([200, 200, 300, 500])}
height={280}
webViewSettings={{
scrollEnabled: false,
}}
/>
<Button title="Update" onPress={change} />
</View>
);
}
I update echarts data using setNewOption
.
My env:
"react-native-echarts-pro": "1.8.4",
"react-native": "0.66.4",
Hope you reply.
I'm sorry I couldn't reproduce it.
But, you can try my test:
import React, { useRef } from "react"; import { View, Button } from "react-native"; import RNEChartsPro from "react-native-echarts-pro"; export default function ChartsComponent() { const echartsRef = new useRef(null); function change() { echartsRef.current.setNewOption({ xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], }, yAxis: { type: "value", }, series: [ { data: [180, 140, 164, 218, 135, 147, 260], type: "line", }, ], }); } function getChartOption(yAxisData) { let xAxisData = []; for (let i = 0; i < 24; i++) { xAxisData.push(i + ""); } let xAxis = { type: "category", nameTextStyle: { color: "#999999", fontWeight: "400", fontSize: 9, lineHeight: 15, }, axisLabel: { showMaxLabel: true, interval: 3, }, axisPointer: { show: true, type: "line", lineStyle: { color: "#BCBCBC", width: 1, type: "solid", }, label: { show: false, }, }, data: xAxisData, }; let yAxis = { type: "value", position: "right", }; let tooltip = { trigger: "axis", position: "right", backgroundColor: "#4D4D4D", borderWidth: 0, formatter: function (params) { ("show source"); return "<span style='color:#ffffff80'>" + params[0].value; }, }; return { xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], }, yAxis: { type: "value", }, tooltip: tooltip, series: [ { data: [150, 230, 224, 218, 135, 147, 260], type: "line", }, ], }; } return ( <View style={{ backgroundColor: "#fff", height: 350, paddingTop: 25, }}> <RNEChartsPro ref={echartsRef} option={getChartOption([200, 200, 300, 500])} height={280} webViewSettings={{ scrollEnabled: false, }} /> <Button title="Update" onPress={change} /> </View> ); }
I update echarts data using
setNewOption
.My env:
"react-native-echarts-pro": "1.8.4", "react-native": "0.66.4",
Hope you reply.
It doest't work too, now I change to use the string, not the function
`getChartOption(yAxisData) { let xAxisData = []; for (let i = 0; i < 24; i++) { xAxisData.push(i+""); }