javascript - amchart 点击时更改子弹

标签 javascript jquery amcharts

我正在尝试更改我点击的项目符号的图像(在 amchart 中) 并且不会产生任何影响。

我正在尝试拥有一个事件列表器,并更改函数中项目的属性。但它对用户界面没有任何影响

有人知道为什么吗?

 $(document).ready(function () {

        Try();

    });

    function Randomize() {

        return Math.floor((Math.random() * 10) + 1);
    }

    function Try() {

        var chart = AmCharts.makeChart("chartdiv", {
            "type": "serial",
            "theme": "none",
            "pathToImages": "http://www.amcharts.com/lib/3/images/",
            "dataProvider":

                buildMe()

            ,

            "balloon": {
                "cornerRadius": 6
            },
            "valueAxes": [{
                "duration": "mm",
                "durationUnits": {
                    "hh": "h ",
                    "mm": "min"
                },
                "axisAlpha": 0
            }],
            "graphs": [{
                "bullet": "square",
                "bulletSize": 14,
                "customBullet": "http://www.amcharts.com/lib/3/images/star.png",
                "bulletBorderAlpha": 1,
                "bulletBorderThickness": 1,
                "fillAlphas": 0.3,
                "fillColorsField": "lineColor",
                "legendValueText": "[[value]]",
                "lineColorField": "lineColor",
                "customBulletField": "customBullet",
                "title": "duration",
                "valueField": "duration"
            }],
            "chartScrollbar": {},
            "chartCursor": {
                "categoryBalloonDateFormat": "YYYY MMM DD",
                "cursorAlpha": 0,
                "zoomable": false
            },
            "dataDateFormat": "YYYY-MM-DD",
            "categoryField": "date",
            "categoryAxis": {
                "dateFormats": [{
                    "period": "DD",
                    "format": "DD"
                }, {
                    "period": "WW",
                    "format": "MMM DD"
                }, {
                    "period": "MM",
                    "format": "MMM"
                }, {
                    "period": "YYYY",
                    "format": "YYYY"
                }],
                "parseDates": true,
                "autoGridCount": false,
                "axisColor": "#555555",
                "gridAlpha": 0,
                "gridCount": 50
            }
        });
         var graph = new AmCharts.AmGraph();
        chart.addListener("clickGraphItem", ChangePan,$(this));

    }


    function ChangePan(event) {
        event.item.dataContext.customBullet = "http://www.amcharts.com/lib/3/images/redstar.png";
        event.item.lineColor = "http://www.amcharts.com/lib/3/images/redstar.png";
         console.log(event.item.dataContext.customBullet);
        console.log(event.item);
    }

    function buildMe() {
        console.log('im in ?')
        var mystring = "";
        var year = 0;
        var month = 0;
        var session = 6;
        var training = 7;

        mystring += "[";
        for (var j = 0; j < training + 1; j++) {

            mystring += '{';


            if (Randomize() < 7) {
                mystring += '"lineColor": "#2498d2",';
            }
            else {
                mystring += '"lineColor": "#1153e6",';
            }
            mystring += ' "date": "2015-07-'+ j +'", "duration": ';

            mystring += Randomize();

           // mystring += ',"customBullet": "http://www.amcharts.com/lib/3/images/redstar.png"';

            if (training == j) {
                mystring += "}";
            }
            else {
                mystring += "},";
            }


        }
        mystring += "]";
        console.log(mystring)
        console.log(JSON.parse(mystring))
        return JSON.parse(mystring);
    }

这是我的jsfiddle .

最佳答案

AmCharts 不会监听 dataContext 更改,因此您必须使用 validateData() 自行执行此操作。 但是,当图表完全重新绘制时,该点将失去悬停状态。 Fiddle

关于javascript - amchart 点击时更改子弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28526446/

相关文章:

javascript - AJAX/PHP 多表单 POST 提交

javascript - 在 amcharts 中添加另一个图例字段以显示百分比

javascript - 重复JS函数

javascript - react : Rendering the component in different way

javascript - 当幻灯片处于事件状态时在 html 元素中设置数据属性

jquery - 从我的服务器发送的静态内容(例如 : . css、.js)是否被 gzip 压缩?

jquery - FireFox插件与服务器的连接

javascript - 在 Angular2 中引导多个组件

javascript - 热图不清晰

javascript - AmCharts parseDates 意外行为并合并图表中的所有条形图