1

I am making a chart using AmCharts. This is my stocklegend section.

"stockLegend": {
"valueTextRegular": "[[time]]:[[value]]"
}

(Here, time is Date obj converted from timestamp that was present in json dataset loaded in javascript object used as data provider for chart. "dataProvider": consChartData.Data where Data is an array holding value & time for a data point.)

Using [[time]]:[[value]], what I am getting is this:

enter image description here

The way I want it is like: Dec 23 2017, 5:21:00 IST: 17,686.54. Is there any way to format the [[time]] here in the way I want?

Edit

This question was not solved by How to format a JavaScript date because, if I use that here, it would be like "valueTextRegular":dateFormat("[[time]]") + "[[value]]",. I have to make a new Date object from passed time and then it shows:

"NaN undefined NaN 17,686.54"

in output.

halfer
  • 19,824
  • 17
  • 99
  • 186
Kashyap Kotak
  • 1,888
  • 2
  • 19
  • 38
  • No. If I use that here, it would be like "valueTextRegular":dateFormat("[[time]]") + "[[value]]", I have to make a new Date object from passed time and then it shows "NaN undefined NaN 17,686.54" in output – Kashyap Kotak Dec 23 '17 at 04:55

1 Answers1

2

You will need to use StockLegend's valueFunction to format the date:

"valueFunction": function (panel, value) {

    var category = panel.category;

    if (category && category instanceof Date) {
        // Dec 23 2017, 5:21:00 IST: 17,686.54
        return [AmCharts.formatDate(category, "MMM D YYYY, H:N:SS"), " IST: ", panel.dataContext.value].join("");
    }

    return value;
}

Please check the links below:

Darlesson
  • 5,742
  • 2
  • 21
  • 26