Hello,
Would there be a way to turn off 1 or more series by default from a chart without clicking?
Example I have Serie 1, Serie 2 and Serie 3.
And I want the Serie 1 to be 'Off by default" while displaying Serie 2 and 3
And when the need arise, I could click on Serie 1 manually to add it to chart
Thank you,
Actually encountered an issue like this in the past but I think my work around may be primitive in regards to what youâre trying to achieve.
I create a dummy model for most pages so that I can render visualizations & things in/out of view. For instance, clicking the button âDisplay By Ownerâ updates a field in dummy model to 1, and the chart that has the series by owner is set to render when that field in dummy model is 1. And the âDisplay by Repâ basically does the inverse action (while replacing the other chart).Â
So what if you created two charts, one with series 1-2 and the other series 1-3. By default display the series 1-2. Add a button above chart that updates ______ field in your dummy model, which then triggers conditional rendering of series 1-2 out and conditionally renders series 1-3 in.Â
Erikâs answer is interesting. Â But you can also do this with just one chart.Â
Each Series can be a separate model.
Set each model to not load data on page load.
On your page -Â Add a button for each model that has the âquery modelâ action.Â
Add a second button for each model that has the âremove all rowsâ action.Â
Conditionally render these buttons so only one shows (based on the presense or absense of model data)
So thenâŚ
On page load your chart will be blank.Â
When you click the âadd series 1â button it will appear in the chart.  (same for series 2 and 3 and 4âŚ)
When you click the âremove series 1â button it will disappear from the chart.Â
There you go.Â
I think there must be a better solution to this. You can click on a series in the chart and it disables. Iâve seen High Charts implementations elsewhere where a series is disabled by default. Thereâs a way to code for that, and it would be great if Skuid implemented that into the visualization component so you could declaratively decide whether to show it or not.Â
I was playing around with Jackâs suggesting, and I did find two things you can do:
-
you can target the element that has the series name under the chart, and execute a click event on it, utilizing the existing functionality to show or hide the series. I was able to add a class to my series via the split template and then target that class to execute the click event.
-
You can call the Highcharts api. The code Highcharts.charts[0].series[2].setVisible(false) set my 3rd series (zero indexed) to be turned off and refreshed the chart. If I had multiple charts on the page, I am not sure how to know which one is which, I havenât figured out how to go from the element to the highchart, or how to relatively reference the series, but hopefully this helps!
Taking slight inspiration from nkovashâs answer, the following is do-able in v1 and v2:
On advanced tab, add a âBefore-render snippetâ that look similar to bellow:
var graphObj = arguments[0],
$ = skuid.$;
for(let idx = 0; idx < graphObj.series.length; idx++){
if(graphObj.series[idx].name === 'Your Series Name'){
graphObj.series[idx].visible = false
}
}
Best,
Lukas
Thatâs awesome @lukaspovilonis!
I didnât realize we would have the chart object as an argument! How does that work?
Originally, I was running my script after page load, developing it through the console, so the visible = false wouldnât re-render for me the same way setVisible(false) would, but maybe because your solution is hitting it before render, it is working! I did have to use a similar looping through the series either way because I found some of my models would sometimes come up with no rows which would re-index the series.
Your answer actually solves another problem I created for myself of finding my chart on a page of a lot of charts. Since I was running the code after page load, I had to find the right chart to update, and stackoverflow kept recommending a jquery plugin for highcharts that I did not have access to. I couldnât ever figure out how to get into the highcharts api from any DOM elements, but I was able to use the same looping strategy through the Highcharts.chart
array to find the chart with the matching title. However, the solution you provided bypasses the need to find the chart and applies it directly. I will put the code below though, in case anyone needs to find their chart for modification after page load.
var charts = Highcharts.charts;
var chartIndex = -1;
for (var i = 0; i < charts.length; i++)
{
if (charts[i] !== undefined && charts[i].title.textStr == 'Your Chart Name') {
chartIndex = i;
}
}
First of all, glad I could help.
Skuid passes an object to snippet, you can explore available information by either adding console.log('beforeRenderSnippet: ', {graphObj })
to code I mentioned above. This will print the object into the console.
Or, you can explore it during run time via the browser console, as bellow:
skuid.runtime.getPage(<pageName>).$C(<componentId>).getHCConfig();
As you will observe, the object you receive in the snippet is a subset of information that is available to you if use your method @nkovash . Another approach to your solution would be to get the information directly from the component as bellow:
skuid.runtime.getPage(<pageName>).$C(<componentId>).getHighchartsObject()
Note, if you want to use it in JS snippet (instead of console), just replace skuid.runtime.getPage(<pageName>)
with skuid
If you're using chart set with multiple charts, the following can also can be useful for other problems:
skuid.runtime.getPage('Overview').$C('OverviewHighchartsChart1').chartSet
Best,
Lukas