Javascript 无法在haxis上显示刻度
我试图在haxis上显示刻度值。下面是动态获取数据并生成柱状图的代码。 问题在于以下代码没有显示h轴dynamicTicks,在h轴上它显示cData中{“v”:i,“f”:hAxisValue}的f:property中给定的值。在演示示例中也是如此,但在我的本地应用程序中应用时,它不会在haxis上显示ticks值。有什么建议吗Javascript 无法在haxis上显示刻度,javascript,angularjs,charts,google-visualization,Javascript,Angularjs,Charts,Google Visualization,我试图在haxis上显示刻度值。下面是动态获取数据并生成柱状图的代码。 问题在于以下代码没有显示h轴dynamicTicks,在h轴上它显示cData中{“v”:i,“f”:hAxisValue}的f:property中给定的值。在演示示例中也是如此,但在我的本地应用程序中应用时,它不会在haxis上显示ticks值。有什么建议吗 app.controller('myController', ['$scope', '$uibModal', 'MyService', function ($scop
app.controller('myController', ['$scope', '$uibModal', 'MyService', function ($scope, $uibModal, MyService) {
$scope.chart = {};
$scope.chart.type = "ColumnChart";
$scope.chart.displayed = false;
var dynamicTicks = [];
$scope.chart.options = {
focusTarget: 'category',
"fill": 20,
"displayExactValues": true,
"isStacked": 'true',
tooltip: {text: 'value',textStyle: {fontName: '"Arial"'}},
hAxis: {
titleTextStyle: {bold: 'true'},
slantedText: false,
ticks: dynamicTicks
},
};
$scope.chart.view = {
columns: [0, 1, 2, 3]
};
$scope.chart.data = {
"cols": [
{id: "label", label: "Label", type: "string"},
{id: "count", label: "Count", type: "number"},
{id: "pizza", label: "Pizza", type: "number"},
{id: "softDrink", label: "SoftDrink", type: "number"},
]
};
$scope.loadMyChart = function () {
MyService.getChartData().then(
function (response) {
$scope.myResponse= response;
//check for error
var count = 0;
var pizza = 0;
var softDrink = 0;
var myRows = [];
$scope.chart.data.rows = {};
var i = 0; var cData=[];
angular.forEach($scope.myResponse, function (value, key) {
count = value.myData.count;
pizza = value.myData.pizza;
softDrink = value.myData.softDrnk;
hAxisValue = value.myData.title;
cData = {
"c": [{"v": i, "f": hAxisValue}, {"v": passsed},
{"v": failed},
{"v": notExecute}, {"v": key}]
};
myRows.push(cData); i++;
});
alert("cData.length " + i);
//assign the haxis ticks values
for (var j = 0; j < i; j++) {
alert("in for" + j + "Series" + (j+1)); //This alert is being executed..
dynamicTicks.push({
v: j, /*cData[j].c[0].v - when this is used, it is showing the error angular.min.js:sourcemap:119 TypeError: Cannot read property 'c' of undefined and chart is not displayed*/
f: 'Series ' + (j + 1)
});
}
$scope.chart.data.rows = myRows;
},
}
$scope.loadMyChart();
}]);
app.controller('myController',['$scope','$uibModal','MyService',函数($scope,$uibModal,MyService){
$scope.chart={};
$scope.chart.type=“ColumnChart”;
$scope.chart.displated=false;
var dynamicTicks=[];
$scope.chart.options={
焦点目标:“类别”,
“填充”:20,
“displayExactValues”:正确,
“isStacked”:“正确”,
工具提示:{text:'value',text样式:{fontName:''Arial'}},
哈克斯:{
titleTextStyle:{bold:'true'},
斜体文字:假,
滴答声:动态
},
};
$scope.chart.view={
列:[0,1,2,3]
};
$scope.chart.data={
“科尔斯”:[
{id:“label”,label:“label”,type:“string”},
{id:“count”,标签:“count”,类型:“number”},
{id:“pizza”,标签:“pizza”,类型:“number”},
{id:“软饮料”,标签:“软饮料”,类型:“编号”},
]
};
$scope.loadMyChart=函数(){
MyService.getChartData()。然后(
功能(响应){
$scope.myResponse=响应;
//检查错误
var计数=0;
var=0;
var软饮料=0;
var myRows=[];
$scope.chart.data.rows={};
VarI=0;VarCDATA=[];
angular.forEach($scope.myResponse,函数(值,键){
count=value.myData.count;
pizza=value.myData.pizza;
软饮料=value.myData.softDrnk;
hAxisValue=value.myData.title;
cData={
“c”:[{“v”:i,“f”:hAxisValue},{“v”:passsed},
{“v”:失败},
{“v”:notExecute},{“v”:key}]
};
推送(cData);i++;
});
警报(“cData.length”+i);
//指定haxis刻度值
对于(var j=0;j
在构建记号后,需要为选项分配记号
for (var j = 0; j < i; j++) {
alert("in for" + j + "Series" + (j+1)); //This alert is being executed..
dynamicTicks.push({
v: j, /*cData[j].c[0].v - when this is used, it is showing the error angular.min.js:sourcemap:119 TypeError: Cannot read property 'c' of undefined and chart is not displayed*/
f: 'Series ' + (j + 1)
});
}
$scope.chart.options.hAxis.ticks = dynamicTicks;
for(var j=0;j
+1对于建议,我仍然看不到haxis上的刻度值。当我对dynamicTicks发出警报时,它会显示一个警报[object object],[object object]…@Whitehat对不起,我没有。我是从DB获取值的。我几乎以静态方式复制了我的代码。当使用cData[j].c[0].v在dynamicicks.push中出现异常angular.min.js:sourcemap:119 TypeError:无法读取未定义的属性“c”,因此将其替换为值j,如上所示。@WhiteHati注意到上面这个问题中发布的代码,第一列为-->{id:“label”,label:“label”,type:“string”}
--要使“记号”
起作用,第一列的类型必须是“'number'
”、“'date'
”等--如所示--记号
不能与离散('string'
)轴一起工作,谢谢它起作用:)。谢谢你的帮助。@WhiteHat