从AmCharts获取范围值

问题描述 投票:1回答:1

我有一个AmCharts工作,这是代码:

var chart = AmCharts.makeChart("chartdiv", {
    "type": "serial",
    "theme": "light",
    "precision":"3",
    "decimalSeparator": ",",
    "thousandsSeparator": ".",
    "legend": {
        "horizontalGap": 10,
        "maxColumns": 3,
        "position": "top",
        "useGraphSettings": false,
        "markerSize": 10,
        "marginTop": 20,
        "autoMargins":true,
        "forceWidth":true,
        "valueAlign":"right",
        "labelWidth":85,
        "valueWidth":85
    },
    "dataProvider": response,
    "synchronizeGrid":true,
    "valueAxes": [{
        "axisAlpha": 0,
        "position": "left",
        "title": "Activos"
    }],
    /*"startDuration": 0.5,*/
    "graphs": graphs,
    "chartScrollbar": {},
    "chartCursor": {
        "cursorPosition": "mouse"
    },
    "categoryField": "diahora",
    "categoryAxis": {
        /*"parseDates": true,*/
        "gridPosition": "start",
        "axisColor": "#DADADA",
        /*"minorGridEnabled": true*/
    },
    "export": {
        "enabled": true,
        "position": "top-right",
        "class": "export-main",
        "menu": [ {
            "title": "Exportar el gráfico a archivo de imagen",
            "label": "Descargar",
            "menu": [ "PNG", "JPG", "PDF" ]
        }]
    }
});

我用ajax调用它:

$.get(url, function(response){

所以,我需要获得在缩放后在浏览器上呈现的图形的X范围的2个值,任何想法?

例如,当图形开始时,轴x的范围是0和100.如果我放大到某个范围,例如40和60,我需要检索这些值(40和60),因为我将它们用于另一个页面中的内容。

那么,如何在每次ajax调用后保存这些范围?

javascript amcharts
1个回答
1
投票

AmCharts提供zoomed事件,它为您提供开始和结束指数/值。您可以使用它并存储您需要的值,例如

AmCharts.makeChart("chartdiv", {
  // ...
  listeners: [{
    event: "zoomed",
    method: function(e) {
     //e.startIndex and e.endIndex gives you the indicies in the dataProvider
     //e.startValue and e.endValue gives you the start and end values
     //e.startDate and e.endDate gives you the start and end dates if you're using parseDates
    }
  }]
});

请注意,zoomed也会在初始加载时调用。如果您不想捕获初始开始/结束值,则可能需要在将这些值存储在后续缩放事件之前跟踪第一个加载。

© www.soinside.com 2019 - 2025. All rights reserved.