I can't get the preview function to work on admin pages. When I click the "Update Preview" button, the preview simply does not show up.

Issue fork charts-3198334

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

extect created an issue. See original summary.

extect’s picture

Title: Preview does not work in Inline Entity Forms (IEF) » Preview does not work on admin pages
Issue summary: View changes
Status: Active » Needs review

Looks like the highcharts library isn't loaded on admin pages. When I put the following in my custom module, previews are working:

function mymodule_page_attachments(array &$attachments) {
  $is_admin = \Drupal::service('router.admin_context')->isAdminRoute();
  if ($is_admin) {
    $attachments['#attached']['library'][] = 'charts_highcharts/highcharts';
    $attachments['#attached']['library'][] = 'charts_highcharts/charts_highcharts';
    return;
  }

}

Maybe we should put sth. like that in the highcharts module itself or even make loading on admin pages available as a setting?

diamondsea’s picture

The preview appears to be drawn off of the saved version of the node. If you save the node and then click Preview, it will appear. If you edit the chart data in the node, the data changes will not be reflected in the chart until you save the node and view the Preview again. Also, make sure that you have selected Highcharts as the charting engine on the page so it will be loaded properly.

srdtwc’s picture

Has the "update preview" button been removed? I am using Highcharts and can see the preview, but the only way I am able to refresh the preview is by toggling the charting library.

srdtwc’s picture

Potentially related: https://www.drupal.org/project/charts/issues/3278438

It seems like "update preview" only appears if the field is collapsed, but it does not work in that situation.

nikathone made their first commit to this issue’s fork.

nikathone’s picture

Need review of the provided MR. If you want to test with the patch file it can be obtained under https://git.drupalcode.org/project/charts/-/merge_requests/31.patch

andileco made their first commit to this issue’s fork.

  • andileco committed c0eabc0 on 5.0.x authored by nikathone
    Issue #3198334 by nikathone, extect, srdtwc, diamondsea: Preview does...
andileco’s picture

Status: Needs review » Fixed

I've tested this and it works much better than previously. Occasionally there's a need to click the "preview" button twice, but no errors are showing.

(As a side note, I need to create a new issue for Chart.js - the data coming from the field is not plotting on the Chart.js chart).

andileco’s picture

Status: Fixed » Needs work

OK, there does actually seem to be something related to Chart.js PREVIEW specifically.

  • andileco committed 920b60d on 5.0.x
    Issue #3198334 by nikathone, andileco, extect, srdtwc, diamondsea:...
andileco’s picture

Status: Needs work » Fixed

For Chart.js preview to work, just needed to change this line in ChartAxisBase.php:

'#axis_type' => 'linear',

to

'#axis_type' => '',

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.