score:0
You can create a directive and use that directive in your htmls..sample code provided here
Directive:
angularAMD.directive('graphDirective', function () {
return {
restrict: 'E',
template: '<div></div>',
scope: {
chartData: "=value",
chartObj: "=?",
page: "=",
},
transclude: true,
replace: true,
link: function ($scope, $element, $attrs) {
// Update when charts data changes
$scope.$watch('chartData', function (value) {
if (!value) {
return;
}
var graphData = {
chart: {
type: 'area',
marginLeft: 65,
marginRight: 1,
marginBottom: 40,
plotBackgroundColor: '#FFF',
backgroundColor: 'transparent',
plotBorderWidth: 1,
plotBorderColor: '#CCC',
animation: false,
renderTo: $element[0]
},
legend: {
enabled: true,
align: 'right',
verticalAlign: 'top',
layout: 'horizontal',
backgroundColor: '#FFF',
borderColor: '#FFF',
borderWidth: 1,
symbolHeight: 20,
symbolWidth:20
},
title: {
text: ''
},
credits: {
enabled: false
},
xAxis: {
min: 0,
categories: [],
title: {
margin: 0,
},
tickInterval: 1,
tickmarkPlacement: 'on',
gridLineWidth: 1,
gridLineColor: '#bbb',
alternateGridColor: '#FFF',
gridZIndex: 1,
startOnTick: true,
endOnTick: false,
minPadding: 0,
maxPadding: 0,
lineWidth: 1
},
yAxis: {
// min: 0,
title: {
margin: 10,
text: 'Target'
},
labels: {
formatter: function () {
return this.value;
}
},
gridLineWidth: 1,
gridLineColor: '#ddd',
lineWidth: 1,
tickInterval: 10
},
plotOptions: {
series: {
states: {
hover: ''
},
},
area: {
//pointStart: 5,
marker: {
enabled: true,
symbol: 'circle',
radius: 4,
lineWidth: 2,
lineColor: '#FFF',
states: {
hover: {
enabled: true
}
}
}
}
},
series: [
{
animation: false,
fillOpacity: 0.4,
name: 'Actual',
color: "#5F8605",
data: [],
connectNulls: true
},
{
animation: false,
fillOpacity: 0.4,
name: 'Strech Goal',
color: "#61DDD3",
data: [],
connectNulls: true
},
{
animation: false,
fillOpacity: 0.4,
name: 'Goal',
color: "#31ABEA",
data: [],
connectNulls: true
}
]
};
graphData.series[0].data = $scope.chartData.series[0].data;
graphData.series[2].data = $scope.chartData.series[2].data;
graphData.series[1].data = $scope.chartData.series[1].data;
graphData.yAxis.min = $scope.chartData.yAxis.min;
graphData.yAxis.max = $scope.chartData.yAxis.max;
graphData.xAxis.categories = $scope.chartData.xAxis.categories;
graphData.yAxis.title.align = 'high';
graphData.yAxis.title.offset = -15;
graphData.yAxis.title.rotation = 0;
graphData.yAxis.title.y = -10;
graphData.xAxis.min = graphData.xAxis.min;
graphData.xAxis.max = $scope.chartData.xAxis.max;
graphData.xAxis.labels = {
formatter: function () {...}
};
graphData.tooltip = {
formatter: function () {..}
};
$scope.chartObj = new Highcharts.Chart(graphData);
}
}, true);
}
};
});
In HTML:
<graph-directive class="cls" page="ctrl.graphPlottingPage" value='ctrl.graphData'></graph-directive >
each graphData you can set via your controllers
score:3
A super simple option for your case is a 'common' controller with 'loadDataChart1' functionality.
//Step 1
app.controller('CommonChartsController', function($scope) {
$scope.createCharts = function (dataMale, dataFem) {
var chartProfiles = $('#container').highcharts();
obj_female = JSON.parse('{ "data":' + dataFem + ' }');
obj_male = JSON.parse('{ "data":' + dataMale + ' }');
chartProfiles.series[0].update(obj_female);
chartProfiles.series[1].update(obj_male);
};
}
//Step 2
app.controller('MainController', function($scope, $controller) {
$controller('CommonChartsController', {
$scope: $scope
});
Item.Rest("datePerUser",null).then(function(totalDatePerUser){
var objectDate = totalDatePerUser.data;
var femDate = objectDate.Chart1Fem;
var mascDate = objectDate.Chart1Masc;
$scope.createCharts(mascDate, femDate);
});
}
//Step 3
app.controller('MenuController', function($scope, $controller) {
$controller('CommonChartsController', {
$scope: $scope
});
PeriodItem.Rest("datePerUser_",Obj).then(function(datePerUserTeste){
var objectDate = datePerUserTeste.data;
newFemDate = objectDate.Chart1Fem;
newMaleDate = objectDate.Chart1Masc;
$scope.createCharts(newMaleDate, newFemDate);
});
}
Source: stackoverflow.com
Related Query
- HighCharts is undefined because multiple Html pages in Javascript file
- Javascript Highcharts v3.0.5 - How to hide Y Axis Title when using multiple Y Axis
- JavaScript code inside TypeScript file .ts not working
- Highcharts - How to make a scatter plot with multiple series from HTML table
- How to export multiple charts in HighCharts to one file (png, jpeg, pdf)
- Plotting multiple series from HTML table generated by Ajax to Highcharts
- passing formatting JavaScript code to HighCharts with JSON
- Highcharts display label for pie chart using html table as data source
- HTML Content to Javascript Code
- HTML table as data source for highstock charts using highcharts
- Uncaught TypeError: Cannot read property '0' of undefined javascript error and with highcharts
- Basic Javascript: How can I link my HTML and Javascript on a Highcharts example?
- How to have multiple highcharts with different series data in vuejs without repeating code
- javascript Highcharts JSON data to HTML table
- Highcharts with values from multiple JSON file
- Highcharts Javascript - Synchronize Chart and Table not working - Cant read property cell of undefined
- Error: Data source must be a URL for refresh | console error | javascript | Highcharts
- Javascript Code not running in Wordpress Pages
- Multiple Highcharts on Primefaces single page, gives javascript error
- Use HTML class as Highcharts table data source
- Highcharts javascript error when other javascript file is included
- javascript display multiple Highcharts using single function
- ReferenceError: Highcharts is not defined while including html file (with JS and CSS ) into other html file
- highcharts with dynamically adding multiple series from JavaScript array name value pair
- Javascript Highcharts Mapping multiple values without showing them all in the chart
- export multiple highcharts with text area for their highcharts to multiple PDF file
- highcharts pass multiple values to tooltip
- JavaScript - Export Div with SVG chart + HTML as and Image
- How can I force multiple y-axis in Highcharts to have a common zero
- How can I read an Excel File with JavaScript (without ActiveXObject)
More Query from same tag
- Gradle sync failed. Basic functionality will not work properly
- how to apply text-align center property to highchart custom label
- Highcharts update breaks previous layout
- Highcharts draggable glitchy tooltip
- Organization Chart Double Color in 1 Box
- HighCharts: automatic x-axis issue in presence of missing data values
- How to make stacked column chart percentages exceed 100% in highcharts
- Remove the Z Axis Column Line in Highcharts 3D
- how to show one more array in the tooltip using highchart?
- Highcharts drill-down using table element as data-source
- Why try catch around highchart constructor does not catch error#12 but error#19?
- passing formatting JavaScript code to HighCharts with JSON
- Highstock don't draw any
- Trouble parsing XML into JSON - Javascript
- Highcharts tooltip background according to line
- Cannot plot scatter and columnrange graph with multiple y-axis
- Highcharts stacked bar data
- HighCharts Stacked Column Adding Onclick Event to the chart
- dataLabels for bar chart in Highcharts not displaying for null values in 3.0.8
- get json data from my controller in highcharts.js
- Highcharts is rounding off the decimal values to 0. How to avoid it?
- Unable to set colors in Highstock charts
- Highcharts Pie chart not accepting values
- make xaxis datalabels have same color like bar Highcharts
- Highcharts-more.js doesn't work in vue-cli project
- highchart with dual axis breakpoint and drag point
- Drilldown multiple levels and multiple type Highchart
- Highcharts tooltip overflow is hidden
- Display count of grouped points on Highcharts dataGrouping
- How to change the width of "yAxis label" in HighChart?