AmCharts中的数据点标签

时间:2013-03-05 04:43:57

标签: graph charts amcharts

我正在使用Amcharts并使用javascript创建了一个散点图。我想在生成的图表的每个数据点上显示我自己的自定义标签(即公司名称和上一财政年度)。

这是我生成的图表:

enter image description here

我的代码

<script type="text/javascript">

    var chartScatter;
    var chartDataScatter = 
    [{
        ax: 5000000,
        ay: 5.60,
        company :'Peer A 19992340N FYE 30 Jun 2012'
     },
     {
         ax: 500000,
         ay: 3.20,
         company: 'Peer B 19992340N FYE 31 Mar 2012'
     },
     {
         ax: 5000000,
         ay: 2.90,
         company: 'Peer C 19992340N FYE 31 Mar 2012'
     },
     {
         ax: 75000000,
         ay: 0.52,
         company: 'Filing company 19992340N FYE 31 Dec 2011'
    }];

    AmCharts.ready(function () {
        // XY CHART
        chartScatter = new AmCharts.AmXYChart();
        chartScatter.pathToImages = "http://www.amcharts.com/lib/images/";
        //chartScatter.marginRight = 0;
        chartScatter.marginTop = 0;
        chartScatter.autoMarginOffset = 5;

        //chartScatter.addTitle("Net profit margin comparison against three peers and industry median", 12);
        chartScatter.addTitle(" ");
        chartScatter.dataProvider = chartDataScatter;
        chartScatter.startDuration = 1;

        chartScatter.addLabel(420, 100, '3 peers average= 3.05');
        chartScatter.addLabel(420, 133, 'Industry median = 1.3');


        // AXES
        // X
        var xAxis1 = new AmCharts.ValueAxis();
        xAxis1.position = "bottom";
        xAxis1.axisAlpha = 0;
        xAxis1.autoGridCount = true;
        xAxis1.addTitle('Revenue');
        chartScatter.addValueAxis(xAxis1);

        // Y
        var yAxis1 = new AmCharts.ValueAxis();
        yAxis1.position = "left";
        yAxis1.axisAlpha = 0;
        yAxis1.autoGridCount = true;
        yAxis1.addTitle('Current ratio');
        chartScatter.addValueAxis(yAxis1);

        // GRAPHS
        // triangles up            
        var graph12 = new AmCharts.AmGraph();
        graph12.lineColor = "#FF6600";
        graph12.xField = "ax";
        graph12.yField = "ay";
        graph12.lineAlpha = 0;
        graph12.bullet = "triangleUp";
        graph12.balloonText = "[[company]]";
        graph12.data_label = "[[company]]";
        chartScatter.addGraph(graph12);

        var trendLine = new AmCharts.TrendLine();
        trendLine.lineColor = "#FF6600";
        trendLine.initialXValue = 1;
        trendLine.initialValue = 2;
        trendLine.finalXValue = 12;
        trendLine.finalValue = 11;
        chartScatter.addTrendLine(trendLine);

       chartScatter.addTrendLine(trendLine);

        // CURSOR
        var chartCursor = new AmCharts.ChartCursor();
        chartScatter.addChartCursor(chartCursor);

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

        // WRITE                                                
        chartScatter.write("chartdivScatter");
    });

1 个答案:

答案 0 :(得分:1)

AmGraph没有data_label属性。请改用labelText。