amchart在网格之间添加标签

时间:2016-07-15 10:16:32

标签: grid lines labels amcharts

enter image description here

我需要在两个轴上添加差异为10的标签(网格之间各一个),不会影响当前的网格数量。因此网格线的数量应保持为11,标签数量将达到21。希望清除我的查询。以上是我的图表,这是代码 -

var chart = AmCharts.makeChart("chartdiv", {                      
    "type": "xy",
    "dataProvider": json,   
    "valueAxes":
    [                                           
        {
            "id":"my_y",
            "autoGridCount": false,
            "position": "right",
            "tickLength":0,
            "gridThickness":0.25,
            "minimum":-100,
            "maximum":100,                          
            "gridCount": 11, 
            "labelFrequency" : 0.5,
            "gridColor":"black",  
            "gridAlpha":0.50,   
            "labelOffset": -356,
            "axisAlpha":0,      
            "strictGridCount" : true,
        }, 
        {
            "id":"my_x",        
            "autoGridCount": false, 
            "position": "bottom",                       
            "tickLength":0,
            "gridThickness": 0.25,                          
            "minimum":-100,
            "maximum":100,
            "gridCount": 11,

            "labelFrequency" : 0.5,
            "gridColor":"black",
            "gridAlpha":0.50,
            "labelOffset": -320,                    
            "axisAlpha":0,
        },   
    ],
    "borderAlpha" : 0, 
    "startDuration": 0, 

    "legend":[{                     
        "useGraphSettings": false,
        "verticalGap":0,
    }],
    "guides":[
                {
                  "fillAlpha": 0.10,
                  "value": -100,
                  "toValue": 100,                         
                }
            ],
    "graphs": 
    [                                
        {
            "id":"g1",
            "lineColor": "#FF6600",
            "bulletBorderThickness": 1,
            "hideBulletsCount": 30,
            "animationDuration":0,
            "balloonText": "[[value]]",
            "bullet": "circle",
            "lineAlpha": 0,
            "valueField": "value",
            "xField": "x",
            "yField": "y",
            "fillAlphas": 0,
            "bulletBorderAlpha": 0,
            "minBulletSize": 30,
            "maxBulletSize": 30,
            "labelText":"[[x]]",
            "labelPosition":"inside",
            "markerType" : "none",
            "switchable":false,
        }, 
    ],
    "marginLeft": 20,
    "marginBottom": 20,         
    "export": {
    "enabled": true,
    "menu" : [],
    },
}); 

PS:我试图更改labelFrequency值,但我认为它不会超过1。

1 个答案:

答案 0 :(得分:2)

您可以假设labelFrequency不能设置为低于1的任何值,或者非整数。

我能想到的唯一解决方法是将gridCount增加到以您想要的增量显示标签的数字。即21。

然后完全禁用网格线。 (gridAlpha: 0

最后使用指南以您需要显示行的值显示行。即:

{
  "id": "my_y",
  "autoGridCount": false,
  "position": "right",
  "tickLength": 0,
  "gridThickness": 0.25,
  "minimum": -100,
  "maximum": 100,
  "gridCount": 21,
  "labelFrequency": 0.5,
  "gridColor": "black",
  "gridAlpha": 0,
  "labelOffset": -356,
  "axisAlpha": 0,
  "strictGridCount": true,
  "guides": [
    { "value": 80, "lineAlpha": 0.5 },
    { "value": 60, "lineAlpha": 0.5 },
    { "value": 40, "lineAlpha": 0.5 },
    { "value": 20, "lineAlpha": 0.5 },
    { "value": 0, "lineAlpha": 0.5 },
    { "value": -20, "lineAlpha": 0.5 },
    { "value": -40, "lineAlpha": 0.5 },
    { "value": -60, "lineAlpha": 0.5 },
    { "value": -80, "lineAlpha": 0.5 }
  ]
}