score:17
Accepted answer
json_encode
is a convenience method to convert an array into json format. to have the output you provided, you will need an array of arrays. each sub-array has keys "name" and "data", where "name" is the item column, and "data" is another array containing values from 2011 and 2012.
$results = mysql_query("...");
$arr = array();
while ($row = mysql_fetch_assoc($results))
{
$name = $row['item'];
$data = array($row['2011'], $row['2012']);
$arr[] = array('name' => $name, 'data' => $data);
}
echo json_encode($arr);
score:3
- loop through the database results and put the results in an array
- json encode the array
Source: stackoverflow.com
Related Query
- how to use highcharts tooltip formatter in python code
- How to create seriesfor Highcharts from JSON data to use
- How to use json data as highcharts Pie Chart?
- How do you correctly encode JSON from MYSQL, ready for Highcharts
- How can I create a specific Json output for use with Highcharts?
- how to use json for Wind rose polar highchart insted of table data
- How to use a custom JSON map in Highmaps
- How can i set the json encode result to the highchart series data using getJSON
- How To Use Highmaps Data In JSON Not Labeled 'value'
- Parsing JSON for use with Highcharts using jquery .parseJSON or JSON.parse: how to remove quotes from function calls for formatters?
- how can I use rangeselector and navigation in highcharts in the given code
- How can I use json Data inside of my component state invalid when trying to use said data inside a variable?
- How to use custom JSON (not GeoJSON) with Highcharts map?
- How to use the tooltip formatter and still display chart color (like it does by default)?
- How to use highcharts with angular 5?
- How can I use chart tooltip formatter in react-highcharts?
- How To Use Epoch Time With Highcharts Series Data?
- how to use json_encode
- How to pass json data to highcharts series?
- HighCharts: How to use reflow to allow auto-resize after changing size
- How to use highcharts with princeXML?
- Highcharts how to use JavaScript variable as series data source?
- How to use dotnet highcharts dll to show HighCharts in MVC3?
- Highcharts: How to load data from JSON to xAxis.categories and series.data?
- Query regarding why and how to use highcharts license
- How to use highstocks navigator on a highchart
- How to import Proj4js to use with Highmaps?
- how to parse json into highcharts
- How to use this highchart map in reactJS
- How to output JSON in python so it can be used for Geckoboard's Highcharts plugin
More Query from same tag
- Highcharts with Google Analytics Oauth 2.0
- Highcharts -- Getting categories from mysql
- Highcharts load pointStart from JSON. Milliseconds to UTC time?
- Can we have multiple callout in timeline chart for single point?
- Highcharts parse CSV
- how to fix tooltip after highchart upgrade
- Highstocks / Highcharts API : how to add spline/line to already rendered chart?
- Highcharts - Stacked bar chart - Remove axis
- Generate highcharts from v-for not populating all graphs with data
- Highcharts columns are thin when 10+ series displayed
- Create a Hicharts Polar chart with lines rather than segments
- When using canvg to convert Highchart SVG into PNG, all text appears twice - how to solve?
- Escape c# class property from JSON serialization (to remove quotes)
- change navigator date format in highstock
- highCharts overlay dataLabels
- Highcharts losing smooth zoom effect
- Highchart columnrange with scrollbar
- xAxis Categories Highcharts
- Title of highchart rendering bad
- What means '404 2716' when trying to run JavaScript library with Django?
- Highstock/Highchart scatter points in combined graph
- Highcharts Image click event
- Highcharts column chart: create color groups
- Reloading HighCharts data using Ajax
- Click on the chart to zoom chart
- How to change selected point styles in Highcharts?
- Highcharts columnrange dataLabel x,y positioning ignored
- HighCharts - Show categories in x axis intead of the value of x in Bubble Chart
- Highcharts - Possible to change the text zoom to other wording?
- Highstock X-Axis: Categories in Place of Time