в файле commonFunctions.js, загруженном на страницу перед обратной передачей функциидля создания графика, где относительная переменная диаграмма была определена как window.chart = new ...
window.renderPriceGraphs = function(chart_name, min_price_usd,
max_price_usd, factory_made, galenic_made,
factory_made_max_min_graph_prices,
factory_made_avg_graph_prices_stats,
galenic_made_max_min_graph_prices = null,
galenic_made_avg_graph_prices_stats = null) {
var max_line = max_price_usd*1.05;
var min_line = min_price_usd*0.90;
//alert("values "+max_price_usd+" "+min_price_usd);
console.log("values ma and min"+max_line+" "+min_line);
if(factory_made == true && galenic_made == true){
//var chart = new CanvasJS.Chart(chart_name, {
window.chart = new CanvasJS.Chart(chart_name, {
animationEnabled: true,
zoomEnabled:true,
theme: "light2",
title:{
text: "Prices per unit of main active ingredients"
},
// subtitles: [{
// text: "High and Low Prices - 2016"
// }],
axisX: {
valueFormatString: "MMM",
intervalType: "month",
interval: 1
},
axisY: {
title: "Price (in USD)",
prefix: "$",
interval: 0.010,
includeZero: false,
stripLines:[
{
value: max_line,
color:"#ff0000",
label: "Max threshold",
labelFontColor: "#ff0000",
showOnTop: true
},
{
value: min_line,
color:"#00bc00",
label: "Min threshold",
labelFontColor: "#00bc00",
showOnTop: true
}
]
},
data: [
{
type: "rangeSplineArea",
showInLegend: true,
legendText: "Factory made max/min Prices",
xValueType: "dateTime",
xValueFormatString: "DD MMM",
yValueFormatString: "$#,##0.#######",
toolTipContent: "Factory made - {x}<br><b>Max:</b> {y[1]}<br><b>Min:</b> {y[0]}",
dataPoints: factory_made_max_min_graph_prices
},
{
type: "spline",
showInLegend: true,
legendText: "Average Factory Prices",
legendMarkerColor: "#dee0ec",
color: "#dee0ec",
lineColor: "#dee0ec",
markerSize: 5,
xValueFormatString: "DD MMMM",
yValueFormatString: "$#,##0.#####",
xValueType: "dateTime",
toolTipContent: "Factory made - <b>{x}</b> </br> Avg: {y}",
dataPoints: factory_made_avg_graph_prices_stats
},
{
type: "rangeSplineArea",
showInLegend: true,
color: "#51bfc3",
fillOpacity: .3,
legendText: "Galenic made max/min Prices",
xValueType: "dateTime",
xValueFormatString: "DD MMM",
yValueFormatString: "$#,##0.#######",
toolTipContent: "Galenic made - {x}<br><b>Max:</b> {y[1]}<br><b>Min:</b> {y[0]}",
dataPoints: galenic_made_max_min_graph_prices
},
{
type: "spline",
showInLegend: true,
legendText: "Average Galenic Prices",
legendMarkerColor: "#a6e6e8",
color: "#a6e6e8",
lineColor: "#a6e6e8",
markerSize: 5,
xValueFormatString: "DD MMMM",
yValueFormatString: "$#,##0.#####",
xValueType: "dateTime",
toolTipContent: "Galenic made - <b>{x}</b> </br> Avg: {y}",
dataPoints: galenic_made_avg_graph_prices_stats
},
]
});
}
if(factory_made == true && galenic_made != true){
var chart = new CanvasJS.Chart(chart_name, {
animationEnabled: true,
zoomEnabled:true,
theme: "light2",
title:{
text: "Prices per unit of main active ingredients"
},
// subtitles: [{
// text: "High and Low Prices - 2016"
// }],
axisX: {
valueFormatString: "MMM",
intervalType: "month",
interval: 1
},
axisY: {
title: "Price (in USD)",
prefix: "$",
interval: 0.010,
includeZero: false,
stripLines:[
{
value: max_line,
color:"#ff0000",
label: "Max threshold",
labelFontColor: "#ff0000",
showOnTop: true
},
{
value: min_line,
color:"#00bc00",
label: "Min threshold",
labelFontColor: "#4b4b4b",
showOnTop: true
}
]
},
data: [
{
type: "rangeSplineArea",
showInLegend: true,
legendText: "Factory made max/min Prices",
xValueType: "dateTime",
xValueFormatString: "DD MMM",
yValueFormatString: "$#,##0.#######",
toolTipContent: "Factory made - {x}<br><b>Max:</b> {y[1]}<br><b>Min:</b> {y[0]}",
dataPoints: factory_made_max_min_graph_prices
},
{
type: "spline",
showInLegend: true,
legendText: "Average Factory Prices",
legendMarkerColor: "#dee0ec",
color: "#dee0ec",
lineColor: "#dee0ec",
markerSize: 5,
xValueFormatString: "DD MMMM",
yValueFormatString: "$#,##0.#####",
xValueType: "dateTime",
toolTipContent: "Factory made - <b>{x}</b> </br> Avg: {y}",
dataPoints: factory_made_avg_graph_prices_stats
},
]
});
}
chart.render();
};