miloschuman / yii2-highcharts

Highcharts widget for Yii 2 Framework
http://www.yiiframework.com/extension/yii2-highcharts-widget/
MIT License
166 stars 63 forks source link

demo chart does not render #53

Closed pswatton closed 7 years ago

pswatton commented 7 years ago

I have copied your example code straight into my view but nothing appears when the view renders.

I am using yii2. Here is the view.

<?php

/ @var $this yii\web\View /

use yii\helpers\Html; use miloschuman\highcharts\Highcharts;

?>

Site Logo
'{ "title": { "text": "Fruit Consumption" }, "xAxis": { "categories": ["Apples", "Bananas", "Oranges"] }, "yAxis": { "title": { "text": "Fruit eaten" } }, "series": [ { "name": "Jane", "data": [1, 0, 4] }, { "name": "John", "data": [5, 7,3] } ] }' ]);?>
pswatton commented 7 years ago

Ive tried to upload the view as a text file as code keeps getting stripped out.

snow.txt

miloschuman commented 7 years ago

It looks like I accidentally left the echo command out of that example. Just put echo in front, like this:

echo Highcharts::widget([
   'options'=>'{
      "title": { "text": "Fruit Consumption" },
      "xAxis": {
         "categories": ["Apples", "Bananas", "Oranges"]
      },
      "yAxis": {
         "title": { "text": "Fruit eaten" }
      },
      "series": [
         { "name": "Jane", "data": [1, 0, 4] },
         { "name": "John", "data": [5, 7,3] }
      ]
   }'
]);
pswatton commented 7 years ago

Thank you for getting back to me.

I tried putting echo in front already and nothing appears. It just puts an opening and closing div with id w0 out.

miloschuman commented 7 years ago

Does your browser console show an error?

pswatton commented 7 years ago

No, does not show any error.

miloschuman commented 7 years ago

I'm not able to reproduce. Try giving your chart an explicit ID, like this:

echo Highcharts::widget([
    'id' => 'moo',
    'options'=>'{
        "title": { "text": "Fruit Consumption" },
        "xAxis": {
            "categories": ["Apples", "Bananas", "Oranges"]
        },
        "yAxis": {
            "title": { "text": "Fruit eaten" }
        },
        "series": [
            { "name": "Jane", "data": [1, 0, 4] },
            { "name": "John", "data": [5, 7,3] }
        ]
    }'
]);

If it works, it means you had another element on the page with the same ID. This can happen in partials and subviews depending on how you render them.

If it doesn't, search the browser's page source for 'moo'. It should occur twice: once for the div's 'id' attribute, and once just before the closing body tag in the script that renders the chart.