首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Amcharts指南

Amcharts指南
EN

Stack Overflow用户
提问于 2016-09-27 15:58:17
回答 1查看 532关注 0票数 0

当我将guides添加到valueAxesSettings中时,即使我选择valueAxesSettingsvalueAxes中,它也不起作用。此外,参考文献中提到的If you change a property after the chart is initialized, you should call stockChart.validateNow() method in order for it to work.valueAxesSettingsvalueAxes有什么不同?什么意思?

代码语言:javascript
复制
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>My first stock chart</title>
<link rel="stylesheet" href="amcharts/style.css" type="text/css">

<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/serial.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<script src="//www.amcharts.com/lib/3/amstock.js"></script>

<style>
    #chartdiv {
        width: 100%;
        height: 500px;
        font-size: 11px;
    }
</style>

<script type="text/javascript">
        AmCharts.makeChart( "chartdiv", {
            "type": "stock",
            "dataDateFormat": "YYYY-MM-DD",
            "dataSets": [ {
                "dataProvider": [ {
                    "date": "2011-06-01",
                    "val": 10
                }, {
                    "date": "2011-06-02",
                    "val": 11
                }, {
                    "date": "2011-06-03",
                    "val": 12
                }, {
                    "date": "2011-06-04",
                    "val": 11
                }, {
                    "date": "2011-06-05",
                    "val": 10
                }, {
                    "date": "2011-06-06",
                    "val": 11
                }, {
                    "date": "2011-06-07",
                    "val": 13
                }, {
                    "date": "2011-06-08",
                    "val": 14
                }, {
                    "date": "2011-06-09",
                    "val": 17
                }, {
                    "date": "2011-06-10",
                    "val": 13
                } ],
                "fieldMappings": [ {
                    "fromField": "val",
                    "toField": "value"
                } ],
                "categoryField": "date"
            } ],

            "panels": [ {

                "legend": {},

                "stockGraphs": [ {
                    "id": "graph1",
                    "valueField": "value",
                    "type": "line",
                    "title": "MyGraph",
                    "fillAlphas": 0
                } ]
            } ],

            "panelsSettings": {
                "startDuration": 1
            },

            "categoryAxesSettings": {
                "dashLength": 5
            },

            "valueAxesSettings": {
                "dashLength": 13,
                "guides": {
                    "value": 10,
                    "tovalue": 12,
                    "lineColor": "#CC0000",
                    "lineAlpha": 1,
                    "fillAlpha": 0.2,
                    "fillColor": "#CC0000",
                    "dashLength": 2,
                    "inside": true,
                }
            },

            "chartScrollbarSettings": {
                "graph": "graph1",
                "graphType": "line",
                "position": "bottom"
            },

            "chartCursorSettings": {
                "valueBalloonsEnabled": true
            },

            "periodSelector": {
                "periods": [ {
                    "period": "DD",
                    "count": 1,
                    "label": "1 day"
                }, {
                    "period": "DD",
                    "selected": true,
                    "count": 5,
                    "label": "5 days"
                }, {
                    "period": "MM",
                    "count": 1,
                    "label": "1 month"
                }, {
                    "period": "YYYY",
                    "count": 1,
                    "label": "1 year"
                }, {
                    "period": "YTD",
                    "label": "YTD"
                }, {
                    "period": "MAX",
                    "label": "MAX"
                } ]
            }
        } );
</script>
</head>
<body>
<div id="chartdiv"></div>
</body>
</html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-28 02:24:55

valueAxesSettingsvalueAxes的全局版本-您在valueAxesSettings中设置的任何内容都将应用于所有常用面板的valueAxes对象。如果要覆盖或设置某个面板的valueAxes中的特定设置,可以在面板中设置valueAxes

代码语言:javascript
复制
"panels": [{
  "valueAxes":[{
    //settings specific to this panel
  }],
  // ...
}, {
  "valueAxes": [{
    //settings specific to this panel
  }]
}

guides属性是一个数组。您将其设置为单个对象,这是不正确的。此外,该属性被称为toValue,而不是"tovalue“-大小写很重要。下面是更正后的valueAxesSettings对象:

代码语言:javascript
复制
  "valueAxesSettings": {
    "dashLength": 13,
    "guides": [{
      "value": 10,
      "toValue": 12,
      "lineColor": "#CC0000",
      "lineAlpha": 1,
      "fillAlpha": 0.2,
      "fillColor": "#CC0000",
      "dashLength": 2,
      "inside": true
    }]
  },

演示:

代码语言:javascript
复制
AmCharts.makeChart("chartdiv", {
  "type": "stock",
  "dataDateFormat": "YYYY-MM-DD",
  "dataSets": [{
    "dataProvider": [{
      "date": "2011-06-01",
      "val": 10
    }, {
      "date": "2011-06-02",
      "val": 11
    }, {
      "date": "2011-06-03",
      "val": 12
    }, {
      "date": "2011-06-04",
      "val": 11
    }, {
      "date": "2011-06-05",
      "val": 10
    }, {
      "date": "2011-06-06",
      "val": 11
    }, {
      "date": "2011-06-07",
      "val": 13
    }, {
      "date": "2011-06-08",
      "val": 14
    }, {
      "date": "2011-06-09",
      "val": 17
    }, {
      "date": "2011-06-10",
      "val": 13
    }],
    "fieldMappings": [{
      "fromField": "val",
      "toField": "value"
    }],
    "categoryField": "date"
  }],

  "panels": [{

    "valueAxes": [{

    }],

    "legend": {},

    "stockGraphs": [{
      "id": "graph1",
      "valueField": "value",
      "type": "line",
      "title": "MyGraph",
      "fillAlphas": 0
    }]
  }],

  "panelsSettings": {
    "startDuration": 1
  },

  "categoryAxesSettings": {
    "dashLength": 5
  },

  "valueAxesSettings": {
    "dashLength": 13,
    "guides": [{
      "value": 10,
      "toValue": 12,
      "lineColor": "#CC0000",
      "lineAlpha": 1,
      "fillAlpha": 0.2,
      "fillColor": "#CC0000",
      "dashLength": 2,
      "inside": true
    }]
  },

  "chartScrollbarSettings": {
    "graph": "graph1",
    "graphType": "line",
    "position": "bottom"
  },

  "chartCursorSettings": {
    "valueBalloonsEnabled": true
  },

  "periodSelector": {
    "periods": [{
      "period": "DD",
      "count": 1,
      "label": "1 day"
    }, {
      "period": "DD",
      "selected": true,
      "count": 5,
      "label": "5 days"
    }, {
      "period": "MM",
      "count": 1,
      "label": "1 month"
    }, {
      "period": "YYYY",
      "count": 1,
      "label": "1 year"
    }, {
      "period": "YTD",
      "label": "YTD"
    }, {
      "period": "MAX",
      "label": "MAX"
    }]
  }
});
代码语言:javascript
复制
#chartdiv {
  width: 100%;
  height: 500px;
  font-size: 11px;
}
代码语言:javascript
复制
<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/serial.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<script src="//www.amcharts.com/lib/3/amstock.js"></script>

<div id="chartdiv"></div>

关于validateNow,如果您更改了股票图表对象中的属性,则需要调用validateNow来使用新设置重新绘制图表。validateData主要用于更改dataSets/dataProvider。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39719203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档