receive json to make my Echart dynamic

0

varechartLine=echarts.init(document.getElementById('echart_line'),theme);echartLine.setOption({title:{text:'Line',subtext:'Mes'},tooltip:{trigger:'axis'},legend:{x:220,y:40,data:['actions1','actions2','actions3']},toolbox:{show:true,feature:{magicType:{show:true,title:{line:'Line',bar:'Bar',stack:'Stack',tiled:'Tiled'},type:['line','bar','stack','tiled']},restore:{show:true,title:"Restore"
        },
        saveAsImage: {
          show: true,
          title: "Save Image"
        }
      }
    },
    calculable: true,
    xAxis: [{
      type: 'category',
      boundaryGap: false,
     // scale:true,
     // splitNumber:12,

      data: ['Mon', Tue', 'Wed', 'Thu', 'Fri'] //Quero receber aqui em JSON
    }],
    yAxis: [{
      type: 'value'
    }],
    series: [{
      name: 'stuff',
      type: 'line',
      smooth: true,
      itemStyle: {
        normal: {
          areaStyle: {
            type: 'default'
          }
        }
      },
      data: [10, 12, 21, 54, 260, 830, 710] // Quero receber aqui em JSON
    }, {
      name: 'stuff',
      type: 'line',
      smooth: true,
      itemStyle: {
        normal: {
          areaStyle: {
            type: 'default'
          }
        }
      },
      data: [30, 182, 434, 791, 390, 30, 10]
    }, {
      name: 'things',
      type: 'line',
      smooth: true,
      itemStyle: {
        normal: {
          areaStyle: {
            type: 'default'
          }
        }
      },
      data: [1320, 1132, 601, 234, 120, 90, 20]
    }]
  });

How can I get my array with querys from PHP to make my chart dynamic? I am in dire need of help. So far I've used JSON a little bit. Thanks

    
asked by anonymous 13.11.2016 / 16:10

2 answers

0

It all depends on how you are making this information available in PHP.

A simple way would be to add a call to jQuery.get() looking for this information.

var echartLine = echarts.init(document.getElementById('echart_line'), theme),
    chartData;

// Faz a chamada ao servidor para buscar os dados do PHP
$.get('/caminho/da/url.php', {dataType: 'json'}, function(retorno) {
    chartData = retorno;
});
...
data: chartData

In PHP you process the data and return it with:

$dados = array(); // aqui um array com os dados que você precisa
header('Content-Type: application/json');
echo json_encode($dados);
exit();
    
14.11.2016 / 13:19
0

Take a look at this link: link , I used this Pen to implement Echarts with Json in my project. In my case I generate a json file and read the same by displaying the data in the chart.

    
19.10.2018 / 20:35