Javascript AmCharts不是带有Json数据源的显示图表
我在ASP.NETMVCWeb应用程序中有两个图表,其中包含Json数据源。我正在使用amcharts来显示图表 在第一种情况下,它起作用了: javascript代码:Javascript AmCharts不是带有Json数据源的显示图表,javascript,json,amcharts,Javascript,Json,Amcharts,我在ASP.NETMVCWeb应用程序中有两个图表,其中包含Json数据源。我正在使用amcharts来显示图表 在第一种情况下,它起作用了: javascript代码: <script type="text/javascript"> $(document).ready(function () { LoadVisual(); }); function LoadVisualAjax() { return $.ajax({
<script type="text/javascript">
$(document).ready(function () {
LoadVisual();
});
function LoadVisualAjax() {
return $.ajax({
type: "Get",
url: '@Url.Action("GetReport5GraphData", "Report")',
});
}
function LoadVisual() {
$.when(LoadVisualAjax()).then((data) => {
DrawChart(data);
}).fail(() => {
alert("Fail to initialize Chart");
});
}
function DrawChart(dataVal) {
console.log(dataVal);
var chart = AmCharts.makeChart("chartdiv",
{
"type": "serial",
"categoryField": "gep",
"startDuration": 1,
"backgroundAlpha": 0.8,
"categoryAxis": {
"autoRotateAngle": 0,
"gridPosition": "start"
},
"trendLines": [],
"graphs": [
{
"balloonColor": "#008000",
"balloonText": "[[title]] of [[category]]:[[value]]",
"fillAlphas": 1,
"fillColors": "#428542",
"id": "AmGraph-1",
"legendColor": "#008000",
"lineColor": "undefined",
"markerType": "triangleUp",
"title": "ok",
"type": "column",
"valueField": "ok"
},
{
"animationPlayed": true,
"balloonText": "[[title]] of [[category]]:[[value]]",
"bulletColor": "#008000",
"customMarker": "",
"fillAlphas": 1,
"id": "AmGraph-2",
"labelText": "",
"markerType": "triangleDown",
"minDistance": 0,
"title": "selejt",
"type": "column",
"valueField": "selejt"
}
],
"guides": [],
"valueAxes": [
{
"id": "ValueAxis-1",
"stackType": "regular",
"title": "Gyártott mennyiség (db)"
}
],
"allLabels": [],
"balloon": {},
"legend": {
"enabled": true,
"useGraphSettings": true
},
"titles": [
{
"id": "Title-1",
"size": 15,
"text": "Előző műszakban gyártott mennyiség"
}
],
"dataProvider": dataVal
});
chart.addListener("rendered");
}
</script>
<script type="text/javascript">
function LoadVisualAjax() {
return $.ajax({
type: "Get",
url: '@Url.Action("GetReport3Data", "Report")',
});
}
function LoadVisual() {
$.when(LoadVisualAjax()).then((data) => {
DrawChart(data);
}).fail(() => {
alert("Fail to initialize Chart");
});
}
function DrawChart(dataVal) {
console.log(dataVal);
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginRight": 40,
"marginLeft": 40,
"autoMarginOffset": 20,
"mouseWheelZoomEnabled": true,
"valueAxes": [{
"id": "ValueAxis-1",
"axisAlpha": 0,
"position": "left",
"ignoreAxisWidth": true,
"title": "Darabszám",
"position": "left",
"autoGridCount": false,
"labelFunction": function (value) {
return Math.round(value);
}
}],
"balloon": {
"borderThickness": 1,
"shadowAlpha": 0,
},
"graphs": [{
"id": "AmGraph-1",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "Cím ",
"type": "column",
"useLineColorForBulletBorder": true,
"valueField": "Db",
"balloonText": "[[category]]: <b style='font-size: 130%'>[[value]]</b>",
}],
"valueScrollbar": {
"oppositeAxis": false,
"offset": 50,
"scrollbarHeight": 10
},
"categoryField": "ErrorCode",
"categoryAxis": {
"parseDates": false,
"equalSpacing": true,
"minPeriod": "DD",
"dashLength": 1,
"minorGridEnabled": true,
},
"legend": {
"useGraphSettings": true,
"position": "top"
},
"export": {
"enabled": false,
},
"dataProvider": dataVal
});
}
$(document).ready(function () {
LoadVisual();
});
$(文档).ready(函数(){
LoadVisual();
});
函数LoadVisualAjax(){
返回$.ajax({
键入:“获取”,
url:'@url.Action(“GetReport5GraphData”,“Report”),
});
}
函数LoadVisual(){
$.when(LoadVisualAjax())。然后((数据)=>{
图纸(数据);
}).失败(()=>{
警报(“未能初始化图表”);
});
}
函数绘图图(dataVal){
console.log(dataVal);
var chart=AmCharts.makeChart(“chartdiv”,
{
“类型”:“串行”,
“类别字段”:“gep”,
“起始持续时间”:1,
“背景Alpha”:0.8,
“分类法”:{
“自动旋转角度”:0,
“网格位置”:“开始”
},
“趋势线”:[],
“图表”:[
{
“气球颜色”:“008000”,
“文本”:“[[类别]]:[[价值]]中的[[标题]]”,
“填充字母”:1,
“填充颜色”:“#428542”,
“id”:“AmGraph-1”,
“legendColor”:“008000”,
“lineColor”:“未定义”,
“markerType”:“triangleUp”,
“标题”:“确定”,
“类型”:“列”,
“valueField”:“ok”
},
{
“动画播放”:对,
“文本”:“[[类别]]:[[价值]]中的[[标题]]”,
“bulletColor”:“008000”,
“自定义标记”:“,
“填充字母”:1,
“id”:“AmGraph-2”,
“标签文本”:“,
“markerType”:“triangleDown”,
“心灵距离”:0,
“标题”:“选择”,
“类型”:“列”,
“valueField”:“selejt”
}
],
“指南”:[],
“价值轴”:[
{
“id”:“ValueAxis-1”,
“stackType”:“常规”,
“标题”:“Gyártott mennyiség(db)”
}
],
“所有标签”:[],
“气球”:{},
“传奇”:{
“启用”:正确,
“useGraphSettings”:正确
},
“头衔”:[
{
“id”:“标题1”,
“尺寸”:15,
“文本”:“Előzőműszakban gyártott mennyiség”
}
],
“数据提供者”:dataVal
});
图表。addListener(“呈现”);
}
dataVal变量值(来自MVC控制器):
工作
在第二种情况下,图表不显示:
javascript代码:
<script type="text/javascript">
$(document).ready(function () {
LoadVisual();
});
function LoadVisualAjax() {
return $.ajax({
type: "Get",
url: '@Url.Action("GetReport5GraphData", "Report")',
});
}
function LoadVisual() {
$.when(LoadVisualAjax()).then((data) => {
DrawChart(data);
}).fail(() => {
alert("Fail to initialize Chart");
});
}
function DrawChart(dataVal) {
console.log(dataVal);
var chart = AmCharts.makeChart("chartdiv",
{
"type": "serial",
"categoryField": "gep",
"startDuration": 1,
"backgroundAlpha": 0.8,
"categoryAxis": {
"autoRotateAngle": 0,
"gridPosition": "start"
},
"trendLines": [],
"graphs": [
{
"balloonColor": "#008000",
"balloonText": "[[title]] of [[category]]:[[value]]",
"fillAlphas": 1,
"fillColors": "#428542",
"id": "AmGraph-1",
"legendColor": "#008000",
"lineColor": "undefined",
"markerType": "triangleUp",
"title": "ok",
"type": "column",
"valueField": "ok"
},
{
"animationPlayed": true,
"balloonText": "[[title]] of [[category]]:[[value]]",
"bulletColor": "#008000",
"customMarker": "",
"fillAlphas": 1,
"id": "AmGraph-2",
"labelText": "",
"markerType": "triangleDown",
"minDistance": 0,
"title": "selejt",
"type": "column",
"valueField": "selejt"
}
],
"guides": [],
"valueAxes": [
{
"id": "ValueAxis-1",
"stackType": "regular",
"title": "Gyártott mennyiség (db)"
}
],
"allLabels": [],
"balloon": {},
"legend": {
"enabled": true,
"useGraphSettings": true
},
"titles": [
{
"id": "Title-1",
"size": 15,
"text": "Előző műszakban gyártott mennyiség"
}
],
"dataProvider": dataVal
});
chart.addListener("rendered");
}
</script>
<script type="text/javascript">
function LoadVisualAjax() {
return $.ajax({
type: "Get",
url: '@Url.Action("GetReport3Data", "Report")',
});
}
function LoadVisual() {
$.when(LoadVisualAjax()).then((data) => {
DrawChart(data);
}).fail(() => {
alert("Fail to initialize Chart");
});
}
function DrawChart(dataVal) {
console.log(dataVal);
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginRight": 40,
"marginLeft": 40,
"autoMarginOffset": 20,
"mouseWheelZoomEnabled": true,
"valueAxes": [{
"id": "ValueAxis-1",
"axisAlpha": 0,
"position": "left",
"ignoreAxisWidth": true,
"title": "Darabszám",
"position": "left",
"autoGridCount": false,
"labelFunction": function (value) {
return Math.round(value);
}
}],
"balloon": {
"borderThickness": 1,
"shadowAlpha": 0,
},
"graphs": [{
"id": "AmGraph-1",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "Cím ",
"type": "column",
"useLineColorForBulletBorder": true,
"valueField": "Db",
"balloonText": "[[category]]: <b style='font-size: 130%'>[[value]]</b>",
}],
"valueScrollbar": {
"oppositeAxis": false,
"offset": 50,
"scrollbarHeight": 10
},
"categoryField": "ErrorCode",
"categoryAxis": {
"parseDates": false,
"equalSpacing": true,
"minPeriod": "DD",
"dashLength": 1,
"minorGridEnabled": true,
},
"legend": {
"useGraphSettings": true,
"position": "top"
},
"export": {
"enabled": false,
},
"dataProvider": dataVal
});
}
$(document).ready(function () {
LoadVisual();
});
函数LoadVisualAjax(){
返回$.ajax({
键入:“获取”,
url:'@url.Action(“GetReport3Data”,“Report”),
});
}
函数LoadVisual(){
$.when(LoadVisualAjax())。然后((数据)=>{
图纸(数据);
}).失败(()=>{
警报(“未能初始化图表”);
});
}
函数绘图图(dataVal){
console.log(dataVal);
var chart=AmCharts.makeChart(“chartdiv”{
“类型”:“串行”,
“主题”:“光”,
“marginRight”:40,
“marginLeft”:40,
“自动补偿”:20,
“MouseweelZoomEnabled”:正确,
“价值轴”:[{
“id”:“ValueAxis-1”,
“axisAlpha”:0,
“位置”:“左”,
“ignoreAxisWidth”:true,
“头衔”:“Darabszám”,
“位置”:“左”,
“自动签名计数”:错误,
“labelFunction”:函数(值){
返回Math.round(值);
}
}],
“气球”:{
“边界厚度”:1,
“阴影Alpha”:0,
},
“图表”:[{
“id”:“AmGraph-1”,
“填充字母”:0.8,
“lineAlpha”:0.2,
“HidebulletScont”:50,
“线宽”:2,
“标题”:“Cím”,
“类型”:“列”,
“useLineColorForBulletBorder”:正确,
“valueField”:“Db”,
“文本”:“[[category]]:[[value]]”,
}],
“值滚动条”:{
“对立轴”:错误,
“偏移量”:50,
“滚动条高度”:10
},
“类别字段”:“错误代码”,
“分类法”:{
“parseDates”:false,
“等间距”:正确,
“minPeriod”:“DD”,
“dashLength”:1,
“minorGridEnabled”:真,
},
“传奇”:{
“useGraphSettings”:正确,
“位置”:“顶部”
},
“出口”:{
“启用”:false,
},
“数据提供者”:dataVal
});
}
$(文档).ready(函数(){
LoadVisual();
});
dataVal变量值(来自MVC控制器):
错
有什么区别?为什么我的第二张图表没有渲染
谢谢你的帮助 Am