score:0
Accepted answer
return just array of data from laravel and in view balde use
var data = json.parse( '{!! json_encode($chartdata) !!}' );
i used this in my code
score:0
wanted to give a code example for how i did this. kind of a pain but from samsquanch i guess this is normal. this does several database calls but still plenty fast for me. this is using laravel framework.
// main chart info
$printerchartarray ["chart"] = array (
'type' => 'line'
);
$printerchartarray ["title"] = array (
"text" => "units per printer"
);
$printerchartarray ["credits"] = array (
"enabled" => false
);
$printerchartarray ["xaxis"] = array (
"categories" => array ()
);
$printerchartarray ["tooltip"] = array (
"valuesuffix" => " units"
);
$printerchartarray ["yaxis"] = array (
"title" => array (
"text" => "units"
)
);
// get series names
$printernames = printjob::distinct()->select('printer')
->wheredate('job_date', '>=', date($from))
->wheredate('job_date', '<=', date($to))
->get();
// loop through series names and set series name and data for high charts
$chartseries = [];
foreach($printernames as $printer)
{
$printname = $printer->printer;
// used where inside join so wouldnt miss dates
// used a calendar table with all dates to fill in missing dates
$data = printjob::select(db::raw('coalesce(sum(print_jobs.quantity), 0) as sum'), db::raw('calendar.datefield'))
->rightjoin('calendar', function($join) use ($printname)
{
$join->on('print_jobs.job_date', '=', 'calendar.datefield')
->where('printer', '=', $printname);
})
->wheredate('calendar.datefield', '>=', date($from))
->wheredate('calendar.datefield', '<=', date($to))
->groupby('calendar.datefield')
->orderby('calendar.datefield', 'asc')
//->tosql();
->get();
//->pluck('sum');
// needed to convert the returned value from a string value to a int value (apparently a driver issue with php and mysql)
foreach ($data as $key => $var) {
$data[$key] = (int)$var->sum;
}
// add series to high chart
$chartseries[] = array(
"name" => $printname,
"data" => $data
);
}
// unessesary to use printjob for this but keeping similar to series to not mess up label
$chartlabel = printjob::select(db::raw('calendar.datefield'))
->rightjoin('calendar', function($join) use ($printname)
{
$join->on('print_jobs.job_date', '=', 'calendar.datefield');
})
->wheredate('calendar.datefield', '>=', date($from))
->wheredate('calendar.datefield', '<=', date($to))
->groupby('calendar.datefield')
->orderby('calendar.datefield', 'asc')
//->tosql(); --- this will show the actual query
//->get(); --- will give array of objects
->pluck('calendar.datefield'); // --- will give a array of just the values wanted
$printerchartarray ["series"] = $chartseries;
$printerchartarray ["xaxis"] = array (
"categories" => $chartlabel
);
//return $printerchartarray; -- used to see output without view
return view('print.charts', compact('jobsbydaylabels', 'jobsbydayvalues', 'unitsbydaylabels', 'unitsbydayvalues', 'printerchartarray'));
and this is the view part
<!-- chart for units by printer by day -->
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div id="printerunitsbyday" style="min-width: 310px; height: 500px; margin: 0 auto"></div>
</div>
</div>
</div>
and this below is the script on the view
$(function() {
$('#printerunitsbyday').highcharts({!! json_encode($printerchartarray) !!})
});
Source: stackoverflow.com
Related Query
- mySQL with PHP to JSON for clientside chart
- JSON data not showing in highstock Candlestick chart using PHP & MYSQL
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Data Conversion from SQL, C# with Linq to JSON for Highcharts Line chart
- Process SQL to JSON through PHP for Bubble Chart
- Passing data from PHP array to Highcharts chart with JSON
- Generate JSON files for Hightcharts with PHP from a TCP string
- JSON for high chart imported with json.load generated error when using json.dump
- Displaying highchart and using php to get data for the chart from mysql database
- highchart mysql json with dropdown select value for where condition
- How to format PHP into the proper string for JSON in pie chart using highchart
- Reload chart data via JSON with Highcharts
- Formatting JSON data monthwise for HighCharts using MySQL
- Add dynamic data to line chart from mysql database with highcharts
- Formatting JSON Data with ColdFusion for HighCharts
- Importing JSON file into Highcharts for Bar Chart Visualization
- Correct JSON for points with custom attributes and 3+ values?
- Highcharts Mysql Json arrays PHP
- Highcharts Mysql Json arrays PHP
- Use MySQL data as the chart data for the cakephp highchart plugin
- Write JSON parser to format data for pie chart (HighCharts)
- How to format my json data for stack column chart in HighCharts
- Php and MySQL with Highchart
- Splitted bar chart for paired data with highcharts
- Highchart - Display JSON Data - MYSQL / PHP
- HighChart Sparkline Chart with dynamic data for the table
- Highcharts - Column chart with empty columns for date in x-axis
- How to use Highcharts React to create chart with multiple lines for same XAxis?
- Posted value is not getting in the where clause with json highcharts-php and mysql
- Retrieving JSON data for Highcharts with multiple series?
More Query from same tag
- Width and show issue when use highchart
- How to feed two values to y axis at a time corresponds to single x axis value in Highchart
- Is there any way to highlight one particular series in highcharts?
- How to add separate annotation style tooltip for Highcharts marker?
- High charts (in Spago BI) - How to allow duplicates?
- How to change color of lable (name) in a highcharts series?
- Highcharts - Legend item padding
- Conditional Symbols in Highcharts
- Legend and Axis titles not showing in Highcharts Graph
- Data coming through socket (nodejs) and push into Highchart
- highcharts doesn't read data, works with fake data
- PhoneGap and Highcharts
- Can the lines in Highcharts appear one after the other?
- not working to update node of network graph
- How to make this code more simple or shorten?
- HighCharts - how to customize the tooltip for dynamically added series
- Rendering a Highcharts.js chart uniformly rather than left-to-right
- How to refresh highcharts (pie chart) data via ajax
- Highcharts Onclick a PieChart slice should refresh the chart
- Highcharts: Rotate VU dials
- How to draw fibonacci retracement in highcharts
- setRequestHeader Error When Saving Canvas as Image on Server
- Uncaught Highcharts error #19: www.highcharts.com/errors/19
- How to find the linkedSeries in Highcharts
- Highchart Data is not supporting
- Slice For Highchart
- Problem in plotting a map graph using highcharter
- Highcharts: create multiple series grouped my month and year using JSON data
- How to show the name of which slice is clicked in high chart-piechart
- Highcharts.js - Switch label axis and hiding legend