通过amchart从X Axis中删除银行假日

时间:2017-08-17 05:06:48

标签: javascript amcharts amstock

我按日期有数据,没有2017/07/172017/07/162017/07/15 因为他们是银行假期。

chartData = new Array();
        chartData[0] = new Array();
        chartData[0].closePrice = 1207;     
        chartData[0].date =  new Date("2017/07/12");
        chartData[1] = new Array();
        chartData[1].closePrice = 1227;     
        chartData[1].date =  new Date("2017/07/13");
        chartData[2] = new Array();
        chartData[2].closePrice = 1216;     
        chartData[2].date =  new Date("2017/07/14");
        chartData[3] = new Array();
        chartData[3].closePrice = 1234;     
        chartData[3].date =  new Date("2017/07/18");

我使用此chartData作为dataProvider来制作图表。

var dataSet = new AmCharts.DataSet();
dataSet.dataProvider = chartData;
dataSet.categoryField = "date";

chart.dataSets = [dataSet];


var stockPanel = new AmCharts.StockPanel();
stockPanel.title = "Stock Main";
stockPanel.id = "stockPanel";
stockPanel.showCategoryAxis = false;
stockPanel.recalculateToPercents = "never";

var valueAxis = new AmCharts.ValueAxis();
valueAxis.dashLength = 5;
stockPanel.addValueAxis(valueAxis);
stockPanel.categoryAxis.dashLength = 5;
stockPanel.categoryAxis.equalSpacing = true; // it doesn't work ....

var graph = new AmCharts.StockGraph();
graph.type = "line";
graph.valueField = "closePrice";
stockPanel.addStockGraph(graph);

然而2017/07/152017/07/16 2017/07/16在X轴上绘制,即使没有数据。

即使.equalSpacing看起来也是徒劳的。

如何删除此???

1 个答案:

答案 0 :(得分:1)

您必须在股票图表的<Play>属性中设置equalSpacing才能生效。

//object-based setup
chart.categoryAxesSettings = new AmCharts.CategoryAxesSettings();
chart.categoryAxesSettings.equalSpacing = true;
//makeChart version
AmCharts.makeChart("chartdiv", {
  // ...
  "categoryAxesSettings": {
    "equalSpacing": true
  },
  // ...
});

categoryAxesSettings