放大[amChart(serial)]时如何自定义标签频率

时间:2016-12-17 00:09:51

标签: amcharts

我正在使用amChart(序列号)来显示图表。我有长度超过4000的数据。我设法通过“labelFunction”显示类别轴的最后一个标签值:formatLabel,。但现在问题是设置标签频率= 10。每当用户放大图表时。 请帮助,提前致谢。

这是代码,

    var  chart= AmCharts.makeChart("rmChart",
        {


            "theme": "light",

            "autoMargins": true, "chartScrollbar": {},
            "type": "serial",
            "categoryField": 'x-distance',
            "legend": {
                "useGraphSettings": false
            },

            "zoomControl": {
                "panControlEnabled": false,
                "zoomControlEnabled": false
            },

            "categoryAxis": {

                "autoGridCount":false,

                "includeHidden":true,

                "dashLength":1,
                " axisAlpha":1,

               "gridPosition": "start",

               "labelFunction" : formatLabel,
              "minHorizontalGap":20,

                "title": "Distance In Meters [m]"
            },
            "chartCursor": {
                "zoomable":true,
                "enabled": true,

            },
            "chartScrollbar": {
                "enabled": false
            },
            "trendLines": [],
            "valueAxes": [{

            }],
            "graphs": [
                {
                    "balloonText": "Distance:[[x-axis]] dB:[[y-axis-0]]",

                    "fillAlphas": 0,
                    "fillToAxis": "x",
                    "lineAlpha": 1,
                    "valueField": "x-axis",
                    "valueField": "y-axis-0",

                    "lineColor": "#FF6600",

                },


            ],
            "guides": [],
            "valueAxes": [
                {
                    "id": "ValueAxis-1",
                    "title": "Strength [dB]",
                    "titleFontSize": 15,

                }
            ],

            "balloon": {},
            "legend": {
                "enabled": false,
                "useGraphSettings": false

            },
            "titles": [
                {
                    "id": "Title-1",
                    "size": 15,
                    "text": data[0]["date"]
                }
            ],
            "dataProvider": data,
            export: {
                enabled: false
            },
            "export": {
                "enabled": true,
                "menu": []
            },
            "chartScrollbar": {

                "enabled":false
            },


        });
  function formatLabel(value, valueText, axis) {
if (valueText.category%2==0) {
                    var lastNumber = (Math.abs(valueText.category) % 10)


                    if (lastNumber==0) {

                        return valueText.category;
                    }

                }
                if (valueText.category==data.length-1) {

                    return valueText.category;
                }
                else{


                    return "";
                }
}

这里是jsfiddle的链接

https://jsfiddle.net/8zw9h007/10/

0 个答案:

没有答案