我正在尝试使用AmStockChart版本2创建一个图表,唯一不起作用的是我想在类别轴中使用数字而不是日期
为此,我还添加了以下javascript但仍在工作
var catAxis = new AmCharts.CategoryAxis();
catAxis.parseDates = false;
chart.categoryAxis = catAxis;
完整的JAVASCRIPT代码
var stockPanel1 = new AmCharts.StockPanel();
stockPanel1.showCategoryAxis = true;
stockPanel1.recalculateToPercents = "never";
// Axis /////////////////////////////////////////////
var valAxis1 = new AmCharts.ValueAxis();
valAxis1.position = "left";
valAxis1.inside = false;
valAxis1.gridAlpha = 1;
valAxis1.gridColor = "#ededee";
valAxis1.color = "#808285";
// Graph ///////////////////////////////////////////
var graph = new AmCharts.StockGraph();
graph.valueField = "Value";
graph.valueAxis = valAxis1;
graph.comparable = true;
graph.compareField = "Value";
graph.periodValue = "Open";
graph.lineThickness = 2;
graph.compareGraphLineThickness = 2;
stockPanel1.addStockGraph(graph);
stockPanel1.addValueAxis(valAxis1);
chart.panels = [stockPanel1];
// create stock legend
var stockLegend1 = new AmCharts.StockLegend();
stockLegend1.valueWidth = 100;
stockLegend1.markerType = "line";
stockPanel1.stockLegend = stockLegend1;
//legend settings
var legendSettings = new AmCharts.LegendSettings();
legendSettings.markerBorderThickness = 6;
legendSettings.markerSize = 29;
legendSettings.color = "#808285";
chart.legendSettings = legendSettings;
// OTHER SETTINGS ////////////////////////////////////
var sbsettings = new AmCharts.ChartScrollbarSettings();
sbsettings.graph = graph;
sbsettings.backgroundColor = "#d5d7d8";
sbsettings.selectedBackgroundColor = "#FFFFFF";
sbsettings.selectedGraphFillColor = "#dcdbb5";
sbsettings.color = "#808285";
sbsettings.enabled = false;
chart.chartScrollbarSettings = sbsettings;
//category settings
var catAxes = new AmCharts.CategoryAxesSettings();
catAxes.dashLength = 15;
catAxes.gridAlpha = 1;
catAxes.gridColor = "#dcddde";
catAxes.color = "#808285";
chart.categoryAxesSettings = catAxes;
chart.panelsSettings.marginRight = 50;
chart.panelsSettings.marginLeft = 50;
var catAxis = new AmCharts.CategoryAxis();
catAxis.parseDates = false;
chart.categoryAxis = catAxis;
//Changes cursor from red to green
var cursorSettings = new AmCharts.ChartCursorSettings();
cursorSettings.cursorColor = "#8e8c35";
cursorSettings.width = 3;
cursorSettings.zoomable = false;
chart.chartCursorSettings = cursorSettings;
chart.write('chartdiv');
如果您需要更多信息,请与我们联系
答案 0 :(得分:1)
通过从2000年开始类别轴然后再添加1来解决问题。 在amchart中,将设置更改为显示年份的最后两个字符
var catAxes = new AmCharts.CategoryAxesSettings();
catAxes.dateFormats = [{ period: 'fff', format: 'JJ:NN:SS' }, { period: 'ss', format: 'JJ:NN:SS' }, { period: 'mm', format: 'JJ:NN' }, { period: 'hh', format: 'JJ:NN' }, { period: 'DD', format: 'DD' }, { period: 'WW', format: 'MMM DD' }, { period: 'MM', format: 'YY' }, { period: 'YYYY', format: 'YY'}];
chart.categoryAxesSettings = catAxes;
答案 1 :(得分:0)
股票图表不能与非基于日期的类别轴一起使用。您可以改为使用AmXYChart。