【问题标题】:get the range values from AmCharts从 AmCharts 获取范围值
【发布时间】:2018-09-06 18:50:01
【问题描述】:

我有一个 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】:

    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 在初始加载时也会被调用。如果您不想捕获初始开始/结束值,则可能需要先跟踪第一次加载,然后再将这些值存储在后续缩放事件中。

    【讨论】:

      猜你喜欢
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多