Support for non date time x values.

This commit is contained in:
Arik Fraimovich
2013-12-07 13:14:02 +02:00
parent 7068e68b8f
commit cc86cb5ffa
2 changed files with 30 additions and 17 deletions

View File

@@ -37,13 +37,23 @@ angular.module('highchart', [])
if (!length || length == 0) {
scope.chart.showLoading();
} else {
while(scope.chart.series.length > 0) {
scope.chart.series[0].remove(true);
}
scope.chart.counters.color = 0;
if (_.some(scope.series[0].data, function(p) { return angular.isString(p.x) })) {
scope.chart.xAxis[0].update({type: 'category'});
_.each(scope.series, function(s) {
_.each(s.data, function(p) {
p.name = p.x;
delete p.x;
})
})
} else {
scope.chart.xAxis[0].update({type: 'datetime'});
}
scope.chart.counters.color = 0;
_.each(scope.series, function(s) {
scope.chart.addSeries(s);

View File

@@ -6,18 +6,25 @@ var defaultChartOptions = {
"tooltip": {
valueDecimals: 2,
formatter: function () {
var s = '<b>' + moment(this.x).format("DD/MM/YY HH:mm") + '</b>',
pointsCount = this.points.length;
if (moment.isMoment(this.x)) {
var s = '<b>' + moment(this.x).format("DD/MM/YY HH:mm") + '</b>',
pointsCount = this.points.length;
$.each(this.points, function (i, point) {
s += '<br/><span style="color:'+point.series.color+'">' + point.series.name + '</span>: ' +
Highcharts.numberFormat(point.y);
$.each(this.points, function (i, point) {
s += '<br/><span style="color:'+point.series.color+'">' + point.series.name + '</span>: ' +
Highcharts.numberFormat(point.y);
if (pointsCount > 1 && point.percentage) {
s += " (" + Highcharts.numberFormat(point.percentage) + "%)";
}
});
if (pointsCount > 1 && point.percentage) {
s += " (" + Highcharts.numberFormat(point.percentage) + "%)";
}
});
} else {
var s = "<b>" + this.points[0].key + "</b>";
$.each(this.points, function (i, point) {
s+= '<br/><span style="color:'+point.series.color+'">' + point.series.name + '</span>: ' +
Highcharts.numberFormat(point.y);
});
}
return s;
},
@@ -86,11 +93,7 @@ renderers.directive('chartRenderer', function () {
$scope.chartOptions = defaultChartOptions;
$scope.$watch('queryResult && queryResult.getData()', function (data) {
if (!data) {
return;
}
if ($scope.queryResult.getData() == null) {
if (!data || $scope.queryResult.getData() == null) {
$scope.chartSeries.splice(0, $scope.chartSeries.length);
} else {
$scope.chartSeries.splice(0, $scope.chartSeries.length);