score:2
The problem is your query.
It should be like the following.
SELECT x_axis, y_axis FROM yourTableName;
This way you'll get exactly the format that Highcharts
needs. You just have to insert it inside an array.
score:0
probably array combine and than json encode and replace? just in case for diversity;)
<?php
$x_axis = array(
'Safari', 'Opera', 'fireFox'
);
$y_axis = array(
10, 30.4, 50
);
$keyFilled = array_combine($x_axis, $y_axis);
arsort($keyFilled);
$jsonData = json_encode($keyFilled);
$jsonDataReplaced = str_replace(array(',', '{', '}', ':'), array('],[', '[', ']', ','), $jsonData);
echo '<pre>';
var_dump('['.$jsonDataReplaced.']');
?>
output is:
string(45) "[["fireFox",50],["Opera",30.4],["Safari",10]]"
score:1
[<? echo "'". json_encode($x_axis). "', " . json_encode($y_axis) ?>]
Demo: http://codepad.org/G5JAtXWu
Nix that I was confused.
What you want to do is this:
foreach($x_axis as $key=>$x) {
echo "['" . $x . "', " . $y_axis[$key] . "]";
}
Demo: http://codepad.org/SKNk1VaX
To wrap it all up:
$d = array();
foreach($x_axis as $key=>$x) {
$d[] = "['" . $x . "', " . $y_axis[$key] . "]";
}
echo json_encode($d);
score:1
Assuming:
$x_axis = array('Safari', 'Opera', 'Firefox', 'IE', 'Chrome', 'Others');
$y_axis = array(10, 6, 40.5, 20, 10.6, 0.5);
This should work:
$data = array();
$length = count($x_axis);
for ($i = 0; $i < $length; $i++) {
$data[] = array($x_axis[i], $y_axis[i]);
}
Source: stackoverflow.com
Related Query
- DB Array to expected javascript format
- Javascript creating an array in a flat format based on multiple levels
- Array not in correct format in Javascript for use by HighChart
- Optimize JavaScript DrillDown code
- How to convert a JavaScript object to array
- JavaScript code inside TypeScript file .ts not working
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- Javascript - How to display a specific index of an array on Highcharts?
- Passing data to highcharts from javascript array or variable
- Javascript - Highcharts - input data array of arrays
- Highcharts Graph displaying 0 value continuously : Javascript Array
- Getting data from Postgres in JSON format in ROR into a Highcharts javascript
- how to add items to an array dynamically in javascript
- passing formatting JavaScript code to HighCharts with JSON
- Embed javascript code in a django template
- How would I convert this array to usable javascript array?
- Concatenate strings into an array in javascript
- HighCharts and Javascript to pass data as array
- How would I convert this array to this json format
- how do you convert epoch to readable date format in javascript
- Array split with the help of object categories values of array- Javascript - High Chart
- How to create dynamic array fo array in javascript
- Javascript Highcharts: series datalabel formatter function to loop data not formatting all data form the array
- Convert javascript datetime object to the format acceptable by highcharts Date.UTC(2014, 0, 2)
- JavaScript Array to Post or Display
- How to make Javascript output brackets for an Array of Arrays. (For Highcharts)
- Laravel get two value array count from controller in javascript
- javascript array object doesn't work with Hicharts when defined through jinja (Django 2.0)
- HTML Content to Javascript Code
- Multidimensional JSON to javascript array for highcharts
More Query from same tag
- Highcharts area chart with lazy_chart ruby gem
- highcharts scrollbar labels not appearing
- Vue project: object does not support this property or method "hasOwnProperty" IE11
- Export button on highcharts to open new tab
- Highcharts Plugin Recently Broke - "this.init is not a function"
- dynamically hide/show button in highcharts
- Error using Highcharts (>= 8.0.1) function stockChart() in Angular
- How to get multiple data series into Highcharts
- Highcharts navigator error: Invalid negative value for <rect> attribute width
- How to add fullscreen event to a Highchart?
- Show loading highstock
- highcharts multiple line live graph
- High Charts - Show series data of Multiple Charts
- Highcharts tooltip is always the same
- choropleth map of malayasia with range slider JS
- Highcharts complex bar chart design with circular annotation or secondary legend
- Using Highmaps, how can I use jQuery fadeIn/fadeOut to fade the data while keeping the map visible?
- How to change highcharts opacity on hover?
- Highcharts does not display when a line of PHP header('location...') is added
- Is there a limit for Scatter plots using JS?
- how to add highcharts in Datatables child row , from google sheets?
- How to set highchart global options IN R
- Disable legend item click in a Highchart defined as JSON
- Highcharts X-Axis value on top of stacked column
- In semi-overlapped bubble hide behind bubble content upto hidden part in Highcharts
- How to set aria attributes to highcharts tooltips
- How to add a category ID to High Charts Category
- Create a new chart for each new page
- Highchart: Tickmark placement for datetime axis
- highcharts web chart inside a modal