whitebear
whitebear

Reputation: 12433

Make Panels invisible amchart

I would like to make panels visible/invisible by button.

in this sample remove/add panels. But when adding, I need to make a panel and settings again.

I would like to just make panels visible/invisible not delete.

I have googled around and not found samples.

Is it possible??


Thanks to @Robbert reply

I could hide the panel . like this .

    $(".amcharts-stock-panel-div-stockPanel1").hide();

However it does not re-adjust the each panel size.

If I call the

So I try like this .

$(".amcharts-stock-panel-div-stockPanel1").hide();
chart.panels[1].percentHeight = 1;
chart.validateNow();

it hide the panel and adjust the each panel height.

However, if you use validateNow() when percentHeight = 1;

this error happens.

  amcharts.js:26 Uncaught TypeError: Cannot read property 'translate' of undefined
    at b.fixVLine (amcharts.js:26)
    at b.adjustBalloonCoordinate (serial.js:17)
    at b.showBalloon (amcharts.js:5)
    at b.handleCursorMove (serial.js:8)
    at b.dispatchMovedEvent (amcharts.js:27)
    at b.syncWithCursorReal (amcharts.js:28)
    at b.syncWithCursor (amcharts.js:28)
    at b.handleCursorChange (amstock.js:2)
    at b.a.inherits.b.fire (amcharts.js:1)
    at b.dispatchMovedEvent (amcharts.js:27)

my final solution is like this , not use css, but prepare variable panelBack for panel backup.

//removing ...
pos = //panel position.
var panelBack = chart.panels[pos];
chart.removePanel(chart.panels[pos]);
chart.validateNow();

//adding...
chart.addPanelAt(panelBack,1);
chart.validateNow();

Upvotes: 0

Views: 435

Answers (1)

Robbert
Robbert

Reputation: 713

By looking at the source of the demo, you'll see that the second Stock Panel gets a classname of amcharts-stock-panel-div-stockPanel1. You could hide it using CSS:

.amcharts-stock-panel-div-stockPanel1 {
  display: none;
}

.amcharts-stock-panel-div-stockPanel1 * {
  /* hide SVG nodes as well */
  visibility: hidden;
}

However, amCharts itself is not aware that this panel is hidden, so it will not re-adjust the height of the first stock panel when "removing" it.

I would advice following the method as seen in the example.

Upvotes: 1

Related Questions