Javascript amcharts堆叠条形图单击处理程序

Javascript amcharts堆叠条形图单击处理程序,javascript,onclick,amcharts,Javascript,Onclick,Amcharts,我需要这样的东西 我使用的是AmCharts.makeChart,似乎无法整合前面的答案。 有人能帮我用这种方法制作图表,让点击处理程序正常工作吗? 任何帮助都将不胜感激 我当前使用的代码: AmCharts.makeChart("0", { "type": "serial", "pathToImages": "http://cdn.amcharts.com/lib/3/images/", "categoryField": "Not set", "rotate": true, "

我需要这样的东西 我使用的是AmCharts.makeChart,似乎无法整合前面的答案。 有人能帮我用这种方法制作图表,让点击处理程序正常工作吗? 任何帮助都将不胜感激

我当前使用的代码:

AmCharts.makeChart("0",
{
    "type": "serial",
    "pathToImages": "http://cdn.amcharts.com/lib/3/images/",
"categoryField": "Not set",
"rotate": true,
"colors": [
"#45C40E",
"#E82323"
],
"startDuration": 1,
"startEffect": "easeOutSine",
"handDrawScatter": 4,
"handDrawThickness": 11,
"categoryAxis": {
"gridPosition": "start",
"position": "left",
"axisThickness": 0,
"labelFrequency": 0,
"showFirstLabel": false,
"showLastLabel": false,
"tickLength": 0
},
"trendLines": [],
"graphs": [
{
    "balloonText": "[[title]]:[[value]]",
    "bulletField": "Not set",
    "fillAlphas": 1,
    "id": "AmGraph-1",
    "title": "Yes",
    "type": "column",
    "valueField": "column-1",
    "visibleInLegend": false
},
{
    "balloonText": "[[title]]:[[value]]",
    "fillAlphas": 1,
    "id": "AmGraph-2",
    "title": "No",
    "type": "column",
    "valueField": "column-2",
    "visibleInLegend": false
}
],
    "guides": [],
    "valueAxes": [
{
    "id": "ValueAxis-1",
    "stackType": "100%",
    "axisThickness": 0,
    "gridThickness": 0,
    "labelFrequency": 0,
    "labelsEnabled": false,
    "showFirstLabel": false,
    "showLastLabel": false,
    "tickLength": 0,
    "title": ""
}
],
    "allLabels": [],
    "balloon": {},
    "legend": {
    "useGraphSettings": true
},
    "titles": [
{
    "id": "Title-1",
    "size": 22,
    "text": ""

}
],
    "dataProvider": [
{
    "category": "category 1",
    "column-1": "53",
    "column-2": "13"
}
]
    }
);

必须将图表存储在变量中,然后为clickGraphItem事件添加侦听器:


var chart = AmCharts.makeChart("0", {
      "type": "serial",
      "pathToImages": "http://cdn.amcharts.com/lib/3/images/",
      "categoryField": "Not set",
      "rotate": true,
      "colors": [
          "#45C40E",
          "#E82323"
      ],
      "startDuration": 1,
      "startEffect": "easeOutSine",
      "handDrawScatter": 4,
      "handDrawThickness": 11,
      "categoryAxis": {
          "gridPosition": "start",
          "position": "left",
          "axisThickness": 0,
          "labelFrequency": 0,
          "showFirstLabel": false,
          "showLastLabel": false,
          "tickLength": 0
      },
      "trendLines": [],
      "graphs": [{
          "balloonText": "[[title]]:[[value]]",
          "bulletField": "Not set",
          "fillAlphas": 1,
          "id": "AmGraph-1",
          "title": "Yes",
          "type": "column",
          "valueField": "column-1",
          "visibleInLegend": false
      }, {
          "balloonText": "[[title]]:[[value]]",
          "fillAlphas": 1,
          "id": "AmGraph-2",
          "title": "No",
          "type": "column",
          "valueField": "column-2",
          "visibleInLegend": false
      }],
      "guides": [],
      "valueAxes": [{
          "id": "ValueAxis-1",
          "stackType": "100%",
          "axisThickness": 0,
          "gridThickness": 0,
          "labelFrequency": 0,
          "labelsEnabled": false,
          "showFirstLabel": false,
          "showLastLabel": false,
          "tickLength": 0,
          "title": ""
      }],
      "allLabels": [],
      "balloon": {},
      "legend": {
          "useGraphSettings": true
      },
      "titles": [{
          "id": "Title-1",
          "size": 22,
          "text": ""

      }],
      "dataProvider": [{
          "category": "category 1",
          "column-1": "53",
          "column-2": "13"
      }]
  });


chart.addListener("clickGraphItem", handleClick)

function handleClick(event){
    console.log(event);
}

必须将图表存储在变量中,然后为clickGraphItem事件添加侦听器:


var chart = AmCharts.makeChart("0", {
      "type": "serial",
      "pathToImages": "http://cdn.amcharts.com/lib/3/images/",
      "categoryField": "Not set",
      "rotate": true,
      "colors": [
          "#45C40E",
          "#E82323"
      ],
      "startDuration": 1,
      "startEffect": "easeOutSine",
      "handDrawScatter": 4,
      "handDrawThickness": 11,
      "categoryAxis": {
          "gridPosition": "start",
          "position": "left",
          "axisThickness": 0,
          "labelFrequency": 0,
          "showFirstLabel": false,
          "showLastLabel": false,
          "tickLength": 0
      },
      "trendLines": [],
      "graphs": [{
          "balloonText": "[[title]]:[[value]]",
          "bulletField": "Not set",
          "fillAlphas": 1,
          "id": "AmGraph-1",
          "title": "Yes",
          "type": "column",
          "valueField": "column-1",
          "visibleInLegend": false
      }, {
          "balloonText": "[[title]]:[[value]]",
          "fillAlphas": 1,
          "id": "AmGraph-2",
          "title": "No",
          "type": "column",
          "valueField": "column-2",
          "visibleInLegend": false
      }],
      "guides": [],
      "valueAxes": [{
          "id": "ValueAxis-1",
          "stackType": "100%",
          "axisThickness": 0,
          "gridThickness": 0,
          "labelFrequency": 0,
          "labelsEnabled": false,
          "showFirstLabel": false,
          "showLastLabel": false,
          "tickLength": 0,
          "title": ""
      }],
      "allLabels": [],
      "balloon": {},
      "legend": {
          "useGraphSettings": true
      },
      "titles": [{
          "id": "Title-1",
          "size": 22,
          "text": ""

      }],
      "dataProvider": [{
          "category": "category 1",
          "column-1": "53",
          "column-2": "13"
      }]
  });


chart.addListener("clickGraphItem", handleClick)

function handleClick(event){
    console.log(event);
}