Intereting Posts

Заполнение Jqplot с удаленного JSON

Я пытаюсь заполнить гистограмму из внешнего JSON в файле PHP. Я пытаюсь использовать функции AJAX и getJSON для этого, но все еще не смог создать диаграмму.

Вот как выглядит мой формат JSON:

[ { "NAME": "a chart", "VALUES": "[[439, 233, 233, 495],[292, 360, 262, 173],[222, 95, 27, 27]]" } ] 

Вот javascript:

  $(document).ready(function() { urlDataJSON = 'data.php'; $.getJSON(urlDataJSON, function (data) { console.log(data.output); var dataLabels = ['base', 'key', 'pacing', 'emerging']; var dataLines = json[0].VALUES; var chartTitle = json[0].NAME; $.jqplot('chart2', dataLines, { legend: { show: true }, title: chartTitle, seriesDefaults: { renderer: $.jqplot.BarRenderer, pointLabels: { show: true, location: 'e', edgeTolerance: -15 }, shadowAngle: 135, renderOptions: { barDirection: 'horizontal' } }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: dataLabels } } }); }); 

Вы, ребята, знаете, что случилось с моим кодом выше? Если что-нибудь, пожалуйста, дайте мне знать.


EDIT: обновленный код

  var urlDataJSON = 'data.php'; /* var json = [{ "Name": "Poll Results", "Serie": [[2, 5, 4], [4, 1, 7], [6, 3, 1], [3, 4, 2]]}];*/ $.getJSON(urlDataJSON, function (data) { console.log(data); var tick = ['asd','fsdf','asda','fdsf',]; var dataLines = []; var title = []; $.each(data, function (entryindex, entry) { dataLines.push(entry['VALUES']); title.push(entry['NAME']); }); var options = { legend: { show: true }, title: 'Poll Results', seriesDefaults: { renderer: $.jqplot.BarRenderer, pointLabels: { show: true, location: 'e', edgeTolerance: -15 }, shadowAngle: 135, renderOptions: { barDirection: 'horizontal' } }, axes: { xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: tick } } }; var plot = $.jqplot('chart2', [dataLines], options); }); 

Я поставил функцию .each (), чтобы вставлять данные в массив. Теперь граф пуст. Показывается только фон.