Yes, the logic would be the same, however, for showing or hiding a chart, you may use different layers, so that you can show or hide the layers instead.
To do so, you can first create the required DVs on different layers and hide them by default (or show one of them by default), then you can add your scripts to a button or “Value Changed” event of the dynamic element filters.
I’ve created a sample for you and added below script to the Click event of the button. By default, the bubble chart will be displayed on the dashboard (as shown in the screenshot),

but, if the dynamic hierarchy is “ProductID” and the dynamic measure is “OrderQty”, clicking the button would replace the bubble chart with the bar chart.

Please see below scripts:
debugger;
// Returns a view parameter with matching name
var baseViewService = this.getService("BaseViewService");
var dynamicMeasureParameter = baseViewService.currentView.control.viewParameters.filter(function(item) {
return item.name === "viewParameter1";
})[0];
var baseViewService = this.getService("BaseViewService");
var dynamicHierarchyParameter = baseViewService.currentView.control.viewParameters.filter(function(item) {
return item.name === "viewParameter2";
})[0];
// Get the layers
var layerAdapters = this.parentView.layerAdapters;
// Retrieve the selected value in the dynamic element filter
var measureParameterValue= dynamicMeasureParameter.parameterValue.uniqueName;
var hierarchyParameterValue=dynamicHierarchyParameter.parameterValue.uniqueName;
// Hide/Show layers based on the selections of the dynamic element filters
if (measureParameterValue=="OrderQty" && hierarchyParameterValue=="ProductID" ) {
// Show barChartLayer and hide bubbleChartLayer
layerAdapters[2].hidden = true;
layerAdapters[1].hidden = false;
}
else {
// Show bubbleChartLayer and hide barChartLayer
layerAdapters[2].hidden = false;
layerAdapters[1].hidden = true;
}
Alternatively, you can use a similar script to re-visualize the chart instead of hiding one and showing another. This should fit your needs as well.