Trendline AmCharts在没有基于日期的情况下无法运行

时间:2015-12-09 17:32:09

标签: javascript amcharts

您好我在AmCharts中使用Trend Line,当我更改没有日期的值时,它不会显示反之亦然。

这是我的代码:

function drawGraph(amYear) {
            var trendLinesData = trendLines(chartData);

            // AmCharts.ready(function () {
            // SERIAL CHART
            chart = new AmCharts.AmSerialChart();

            chart.dataProvider = chartData;
            chart.dataDateFormat = "YYYY-MM";
            chart.categoryField = "field";
            chart.startDuration = 2;

            // AXES
            // category
            var categoryAxis = chart.categoryAxis;
            categoryAxis.parseDates = false; // as our data is date-based, we set parseDates to true
            categoryAxis.minPeriod = "MM"; // our data is daily, so we set minPeriod to DD
            categoryAxis.gridAlpha = 0.1;
            categoryAxis.minorGridAlpha = 0.1;
            categoryAxis.axisAlpha = 0;
            categoryAxis.minorGridEnabled = true;
            categoryAxis.inside = true;

            // value
            var valueAxis = new AmCharts.ValueAxis();
            valueAxis.title = "Total";
            valueAxis.tickLength = 0;
            valueAxis.axisAlpha = 0;
            valueAxis.showFirstLabel = false;
            valueAxis.showLastLabel = false;
            chart.addValueAxis(valueAxis);

            // GRAPH
            var graph = new AmCharts.AmGraph();
            graph.dashLength = 5;
            graph.lineColor = "#3498db";
            graph.valueField = "value";
            graph.lineThickness = 1;
            chart.addGraph(graph);

            // SCROLLBAR
            var chartScrollbar = new AmCharts.ChartScrollbar();
            chart.addChartScrollbar(chartScrollbar);

            // TREND LINES
            // first trend line
            var trendLine = new AmCharts.TrendLine();
            trendLine.initialValue =  5;
            trendLine.initialXValue =  5;
            trendLine.finalValue =  30;
            trendLine.finalXValue =  40;
            trendLine.lineColor = "#000";

            chart.addTrendLine(trendLine);

            // WRITE
            chart.write("datachart");
        // });
        }

我已经尝试了另一个属性,我调用了chart.validateNow()但它仍然不起作用。 如何解决?

1 个答案:

答案 0 :(得分:0)

在非基于日期的序列图表中(根据您发布的代码似乎正在使用),您需要使用initialCategoryfinalCategory

他们需要完全按照您在数据类别字段中包含的字符串(在您的情况下为field)。

initialXValuefinalXValue仅与XY图表相关。