Graphics with Highcharts, JSON and CodeIgniter

2

Someone to help me how to make a Grafica using Highcharts in CodeIgniter using JSON.

url:('<?= base_url(); ?>index.php/ejemplo/ejemDatos/datos', function (data) {

// create the chart

  Highcharts.stockChart('datos', { //datos es el id de mi 'div' 

      rangeSelector: {
          selected: 1
      },

      title: {
          text: 'Ejemplo'
      },

      series: [{
          name: 'Nº Datos',
          data: nDatos, // nDatos es el resultado de mi JSON
          tooltip: {

          }
      }]
    });
});

This is how I "thought" but the only thing that makes me is to put the div blank, Someone who can help me.

  

The libreri is already loaded.

    
asked by Soldier 07.08.2017 в 23:29
source

1 answer

0

Good morning.

Make a replacement of what you put with the example Single line series by opening the example is provided (in the jsfiddle ):

The original:

Highcharts.stockChart('container', {
    rangeSelector: {
        selected: 1
    },

    title: {
        text: 'AAPL Stock Price'
    },

    series: [{
        name: 'AAPL',
        data: data,
        tooltip: {
            valueDecimals: 2
        }
    }]
});

"leave" (using the part you put):

Highcharts.stockChart('container', { //datos es el id de mi 'div' 

  rangeSelector: {
      selected: 1
  },

  title: {
      text: 'Ejemplo'
  },

  series: [{
      name: 'Nº Datos',
      data: data, // nDatos es el resultado de mi JSON
      tooltip: {

      }
  }]
});

and there was no problem; the graph was generated. Apparently Highcharts or javascript (I do not know who solves it) identifies perfectly if data is the property / data of the Highchart or the parameter (which in your case must contain the JSON) therefore to what you initially raised it would suffice that url:('<?= base_url(); ?>index.php/ejemplo/ejemDatos/datos', function (data) put it as url:('<?= base_url(); ?>index.php/ejemplo/ejemDatos/datos', function (nDatos) or change to nDatos as data any of the 2 as you prefer.

In relation to the fact that your JSON has more than one data; It can be something in it. If you mean that there are several series I suggest you meet the format to generate such series . You should check your JSON for each series it complies with what is acceptable by the Highchart can be something in your JSON (of which it does not share the structure -not real data - structure to check if there is something of more or less) .

    
answered by 09.08.2017 в 02:03