-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visual of graph breaks when changing from having data to none #121
Comments
When there is no data, the Y-axis has no value to display, but we can set the maximum and minimum values to ensure that the y-axis has a value to display. Of course, the maximum value cannot be known, and you can also write a function to handle it, mainly to ensure The legend can be displayed when there is no value. such as this below shown: yAxis: {
type: 'value',
min:0,
axisLabel: {
formatter: '{value}%'
},
max: function (value) {
if(!value.max) return 100;
return value.max + 30;
},
}, I don’t know if this can solve your problem, you can try it |
Thanks for the response I will check it out. I do not want to show either the y-axis or the legend when I have no data. |
I misunderstood. I thought you wanted the legend or y-axis to be displayed regardless of whether there is data. If your problem still cannot be solved or you would like us to provide support, You can describe it in more detail so it's easier to find a suitable solution. |
@yechunxi Thanks you can see whats happening in the video. Probably I will post more of the code in the next few days. Thanks for the response. |
// CHART RELATED
const RoadBikeRef = useRef<any>(null);
useEffect(() => {
const ROAD_BIKE_OPTIONS = {
title: {
show: chartSeries.length === 0,
textStyle: {
color: "#F7F3F0",
fontSize: 20,
},
text: "No data available",
left: "center",
top: "20%",
},
grid: {
right: "2%",
// y2: 300,
height: E_HEIGHT * 0.35,
},
tooltip: {
show: chartSeries.length !== 0,
trigger: "axis",
textStyle: {
color: "#F7F3F0",
},
backgroundColor: "rgba(61, 52, 62, 0.9)",
valueFormatter: function (val) {
return `${val} %`;
},
confine: true,
},
legend: {
data: chartSeries.map((series) => series.name),
icon: "circle",
inactiveColor: "#64605D",
textStyle: {
color: "#F7F3F0",
},
orient: "vertical",
bottom: 0,
left: 0,
// top: "bottom",
// top: -20,
//Paei to legend apo kato. Iparxi overlap provlima (na to kitakso)
},
xAxis: {
type: "category",
data:
currentPeriod === "4 Weeks"
? Object.keys(week_buckets).reduce((arr, key) => {
return arr.concat(key, "", "", "", "", "", "");
}, [])
: categories,
axisLabel: {
interval: 0,
},
axisTick: {
alignWithLabel: true,
},
},
yAxis: {
type: "value",
min: 0,
axisLabel: {
formatter: (val) => Math.ceil(val) + "%",
},
},
series: chartSeries.map((series) => ({
name: series.name,
type: "line",
smooth: true,
data: series.data,
symbol: "circle",
lineStyle: {
type: series.name.includes("Not") ? "dashed" : "solid",
},
})),
};
let chart: any;
if (RoadBikeRef.current) {
chart = echarts.init(RoadBikeRef.current, "light", {
renderer: "svg",
width: E_WIDTH * 0.9,
height: E_HEIGHT * customHeight,
});
chart.setOption(ROAD_BIKE_OPTIONS);
}
return () => chart?.dispose();
}, [chartSeries]); I have one more when changing to TT bike. So whats happening if I have data on my chartSeries road_bike |
Any updates about this one? Currently the only problem we are having with our mobile graphs. |
Bump. Any news? We are almost in time for publishing our app and graphs are one of the main parts. |
I can't reproduced this problem. Can you provide a demo of the reproduction? I see that the x-axis of the chart in your code is variable, but it is not included in the useEffect dependency. |
Sure I will try to create the reproduction later. |
After some debugging I found the problem is happening because of the chart height As you see in my code above for my height im using my device height multiply by a custom height const customHeight: number = useMemo(() => {
return bikePositions.length === 0
? 0.5
: 0.5 + bikePositions.length * 0.023;
}, [bikePositions]); So if my custom height is 0.6(when I have data) and goes 0.5(zero data) we can see the smashed chart. |
Now that you have found the cause of the problem, you can deal with the chart height issue according to the business, so I will close this issue |
I'm sorry I will comment once again. I followed the doc adaptive-size(seems new guide)
Then I created a useEffect that updates that state based on my bikePositions
Lastly I added an extra useRef to resize my graph
The only problem I have (video below) is the flickering (probably double render). Sorry for commenting once again. Thanks for the help in Advance. Screen.Recording.2023-10-12.at.10.16.09.AM.mov |
Screen.Recording.2023-09-21.at.11.49.02.AM.mov
My custom height will change depending of how many positions i have. (This happens to solve my legend vertical problem)
The problem is when I change graphs for example from Road to TT if i have data on Road my TT will be weird. See the video to understand it better. Thanks in advance
The text was updated successfully, but these errors were encountered: