Javascript 如何使amcharts的图形部分动态化
我正在从数据库字段创建amcharts。这是我的代码Javascript 如何使amcharts的图形部分动态化,javascript,jquery,asp.net,json,amcharts,Javascript,Jquery,Asp.net,Json,Amcharts,我正在从数据库字段创建amcharts。这是我的代码 function Categoriesline(data) { debugger; var databind = JSON.parse(data); var
function Categoriesline(data) {
debugger;
var databind = JSON.parse(data);
var chart = AmCharts.makeChart("chartdiv2", {
"theme": "light",
"type": "serial",
"legend": {
"position": "right",
"fontSize": 9
},
"marginRight": 80,
"autoMarginOffset": 20,
"marginTop": 20,
"dataProvider": databind,
"valueAxes": [{
"id": "v1",
"axisAlpha": 0.1
}],
"graphs": [{
"balloonText": "[[category]]<br><b>value: [[value]]</b>",
"bullet": "round",
"bulletBorderAlpha": 1,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "section1",
"valueField": "section1"
}, {
"balloonText": "[[category]]<br><b>value: [[value]]</b>",
"bullet": "round",
"bulletBorderAlpha": 1,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "section2",
"valueField": "section2"
}, {
"balloonText": "[[category]]<br><b>value: [[value]]</b>",
"bullet": "round",
"bulletBorderAlpha": 1,
"hideBulletsCount": 50,
"lineThickness": 2,
"title": "section3",
"valueField": "section3"
}],
"categoryField": "categorydescription",
"categoryAxis": {
"axisAlpha": 0,
"minHorizontalGap": 60
},
"export": {
"enabled": true
}
});
}
我已经添加了json详细信息。你能发布你的json是什么样子吗?@martynasma:附加的json格式。这里的“duration”是我的分类轴,我需要指定“section1”、“section2”等作为值轴,“value”作为值字段。请帮助。如何将此动态值设置为值轴?谢谢。但是你能以文本格式发布数据吗?@martynasma:我已经在讨论中的浏览器窗口中添加了json详细信息。这足够了吗?不。为什么你不能将数据作为数据而不是数据的图像发布?如果你想要帮助,你需要让人们更容易帮助你。为什么要让他们重新键入您的数据?
var graph = [];
var v;
for (var j = 0; j < 6; j++) {
graph[j] = new AmCharts.AmGraph();
graph[j].valueAxis =databind['section'] ; // we have to indicate which value axis should be used
graph[j].title = "Value" + j;
v = j.toString();
graph[j].valueField = databind['value'];
graph[j].bullet = "round";
chart.addGraph(graph[j]);
}
[
{
"Section": "Section1",
"duration": "1MCount",
"value": 15},
{
"Section": "Section2",
"duration": "1MCount",
"value": 20},
{
"Section": "Section1",
"duration": "3MCount",
"value": 10},
{
"Section": "Section2",
"duration": "3MCount",
"value": 7},
{
"Section": "Section3",
"duration": "3MCount",
"value": 12}
]