0
votes

When I add the guides into valueAxesSettings but it doesn't work even I choose valueAxesSettings into valueAxes. Furthermore, what the difference between valueAxesSettings and valueAxes, as the reference said If you change a property after the chart is initialized, you should call stockChart.validateNow() method in order for it to work.? what does it mean?

<!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>
1
When you change the properties after the chart is initialized, you need to call validateNow() so that the graph is redrawn using your new (changed) settings. You cal also call validateData() but it is optional. - Anurag
To expand on @Anurag's comment, you use validateData when you change your chart's data. validateNow doesn't handle that by default unless you set the first parameter to true, e.g. validateNow(true, false) is the equivalent of validateData(). - xorspark

1 Answers

1
votes

valueAxesSettings is a global version of valueAxes - anything you set in valueAxesSettings will be applied to all stock panels' valueAxes objects. If you want to override or set a specific setting in one of your panels' valueAxes, you can set a valueAxes inside the panel:

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

The guides property is an array. You're setting it as a single object, which is incorrect. Also, the property is called toValue, not "tovalue" - the casing is important. Here's the corrected valueAxesSettings object:

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

Demo:

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>

Regarding validateNow, if you change a property in your stock chart object, you need to call validateNow to redraw the chart with your new settings. validateData is primarily used when you make changes to your dataSets/dataProvider.