How would you be able to count how many points are...
# gooddata-ui
m
How would you be able to count how many points are on a linechart using insightview for react?
j
Hello Misael! The InsightView component does not provide this information directly, however I can think of at least two ways to approach this: 1️⃣ You could get the insight definition based on the insight identifier, execute it (either using the Execute component, or directly via API call to executeAfm endpoint), and then count how many raw values the execution response returns; this number should reflect the number of points on a LineChart (or any other chart for that matter). 2️⃣ You could also take more "visual" approach, where you would use some custom JavaScript code to investigate how many SVG elements (that represent the points of a LineChart) are displayed in the insight. May I ask why do you need such information? What is it you're looking for? 🙂
m
Thanks for the response! I will try those approaches. I just wanted to know how many points are present because if there are only 2 or less points then I don't want to render the chart but if there are more than two then render it. It just helps with conditional rendering :)
j
You're very welcome! I see your point, conditional rendering seems like a valid use-case to me. I would recommend approach 1️⃣, simply running the execution "beforehand" and making the decision whether to render the chart or not. There will be two executions happening, but assuming the payload will be the same, our platform will compute the first one, and use a cached result for the second one (provided it was decided to render the chart), so the performance should not be affected by a lot.