当我将guides添加到valueAxesSettings时,即使我选择valueAxesSettings进入valueAxes,它也无法正常工作。
此外,valueAxesSettingsvalueAxes之间的区别(以参考文献If you change a property after the chart is initialized, you should call stockChart.validateNow() method in order for it to work.为例)?这是什么意思?

<!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>

最佳答案

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

"panels": [{
  "valueAxes":[{
    //settings specific to this panel
  }],
  // ...
}, {
  "valueAxes": [{
    //settings specific to this panel
  }]
}


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

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


演示:



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"
    }]
  }
});

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

<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时使用。

10-06 12:10