Here's the code I use to plot a line graph.
var db_query = <?php echo json_encode($db_query_1) ?>;
var chart;
var graph;
/* chart initialization */
var chart = AmCharts.makeChart("plot1", {
type: "serial",
categoryField: "OCCUR_DATE",
graphs: [{
type: "smoothedLine",
theme: "light",
valueField: "FREQ"
}]
})
$.ajax({
type: 'POST',
url: "mySQL.php",
data: {'db_que': db_query},
dataType: 'html',
context: document.body,
global: false,
async:true,
success: function(data) {
//alert(data);
chart.dataProvider = eval(data);
chart.validateNow();
}
});
I'd like to
- Create a separate javascript file with properties defined for each of line, pie, bar etc types of graphs & import that javascript file
replace this:
var chart = AmCharts.makeChart("plot1", { type: "serial", categoryField: "OCCUR_DATE", graphs: [{ type: "smoothedLine", theme: "light", valueField: "FREQ" }] })
with
var chart = AmCharts.makeChart("plot1", options_line_graph);
I'd like to be able to pass parameters to the properties for the x-axis & y-axis titles & the graph name. These are at least the very few variable parameters I can think of now. If I can achieve this, adding more variable parameters could be done easily I presume.
The reason I ask for help here is, I have over 30 line graphs, 20 pie charts & a few of other types that I will plot. Setting the same set of properties over & over again sounds an inefficient way of doing things.
Could someone please guide/help me?