Jump to content

Change Chart Legend Visible at Runtime


Bernie07

Recommended Posts

Hello,

 

I'm trying to change the Visible state of the UniChart Legend at Runtime like

 

ChartEinsaetzeStatistik.Legend.Visible := CheckEinsaetzeStatistikLegendeAnzeigen.Checked;

 

But nothing happens.

 

What can I do to Change the Legend Visible state of a Chart at Runtime?

 

Best wishes

Bernhard

Link to comment
Share on other sites

Hi,

 

Can you try to use this approach for now: ?!

 

1. In DesignTime:

UniChart1 -> Legend -> Visible -> [True]

2. In RunTime, try to use a toggle method.

 

For example:

procedure TMainForm.UniFormReady(Sender: TObject);
begin
  with UniChart1.JSInterface do
  begin
    JSCall('chart.legend.toggle', [False]); // Hide
    //JSCall('chart.redraw', []);
  end;
end;
  ...
  with UniChart1.JSInterface do
  begin
    JSCall('chart.legend.toggle', [True]); // Show    
    JSCall('chart.redraw', []);
  end;

Best regards.

Link to comment
Share on other sites

Thanks for your answer.

this works, but the place of the legend isn't reused for the chart, if I make the legend invisible.

 

This means, that the chart isn't drawed bigger. I want that the chart is also using the place of the legend because the legend isn't shown anymore.

 

Is there a way to redraw the chart so it is using also the empty place where was the legend drawn before?

 

My Code is now :

  if CheckEinsaetzeStatistikLegendeAnzeigen.Checked then begin
    ChartEinsaetzeStatistik.JSInterface.JSCall('chart.legend.toggle', [true]);
    ChartEinsaetzeStatistik.JSInterface.JSCall('chart.redraw', []);
  end
  else begin
    ChartEinsaetzeStatistik.JSInterface.JSCall('chart.legend.toggle', [false]);
    ChartEinsaetzeStatistik.JSInterface.JSCall('chart.redraw', []);
  end;

 

Best wishes

Bernhard
 

 

 

 

Best wishes

Bernhard

Link to comment
Share on other sites

Hi,

 

Can you try this approach ?!:

 

Show:

  with UniChart1.JSInterface do
  begin
    JSCode(#1'.chart.legend.width='#1'.chart.legend.originalWidth;');
    JSCall('chart.legend.toggle', [True]);     
    JSCall('chart.redraw', []);
  end;

Hide:

  with UniChart1.JSInterface do
  begin
    JSCode(#1'.chart.legend.originalWidth='#1'.chart.legend.width;');
    JSAssign('chart.legend.width', [0]);
    JSCall('chart.legend.toggle', [False]);
    JSCall('chart.redraw', []);
  end;
Link to comment
Share on other sites

  • 1 year later...

Hello,

I have now installed the newest version of unigui. And now the function chart.legend.toggle don't work anymore. I get the error "toggle is no function". I have also tried it with JSProperty instead of JSCall, but then nothing happens. The legend is still visible.

Can I solve this with another code?

Best wishes

Bernhard

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...