我正在通过amcharts开发图表,我希望它选择某些范围,因为我在地图上处理了超过6000个x值。我试图在地图上使用zoomToCategory控件,但是当我使用它时,地图没有出现.. :( ..任何原因???以下是我的代码。:)

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>

        <head>

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>amCharts examples</title>
            <link rel="stylesheet" href="http://localhost/amcharts/images/style.css" type="text/css">
            <script src="http://localhost/amcharts/amcharts.js" type="text/javascript"></script>
            <script type="text/javascript">

                var chart;

                var chartData = JSON.parse('<%=sjson%>');// [{ "Ip": "0", "Count": "10" }, { "Ip": "1", "Count": "11" }, { "Ip": "2", "Count": "12" }, { "Ip": "3", "Count": "13" }, { "Ip": "4", "Count": "14" }, { "Ip": "5", "Count": "15" }, { "Ip": "6", "Count": "16" }, { "Ip": "7", "Count": "17" }, { "Ip": "8", "Count": "18" }, { "Ip": "9", "Count": "19"}];



                AmCharts.ready(function () {
                    // SERIAL CHART
                    chart = new AmCharts.AmSerialChart();
                    chart.dataProvider = chartData;
                    chart.categoryField = "Ip";
                    chart.startDuration = 1;

                    // AXES
                    // category
                    var categoryAxis = chart.categoryAxis;
                    categoryAxis.labelRotation = 90;
                    categoryAxis.gridPosition = "Count";

                    // value
                    // in case you don't want to change default settings of value axis,
                    // you don't need to create it, as one value axis is created automatically.

                    // GRAPH
                    var graph = new AmCharts.AmGraph();
                    graph.valueField = "Count";
                    graph.balloonText = "[[category]]: [[value]]";
                    graph.type = "column";
                    graph.lineAlpha = 0;
                    graph.fillAlphas = 0.8;

                    graph.zoomToCategoryValues("1", "10");
                    chart.addGraph(graph);

                    chart.write("chartdiv");
                });
            </script>

        </head>

        <body>
            <div id="chartdiv" style="width: 100%; height: 400px;"></div>
        </body>

    </html>


请为我提供帮助...在此grpah上钻取x轴非常重要,因为它显示了大量数据。非常感谢:)

最佳答案

图没有zoomToCategoryValues方法,只有图表有。
而且,您无法在图表初始化之前调用此方法。

您应该侦听“ init”或“ dataUpdated”事件,然后调用将进行缩放的方法:

// this line shoulf go to AmCharts.ready function:
chart.addListener("dataUpdated", zoomChart);

// this is a method which will be called after the event is fired:
function zoomChart() {
     chart.zoomToCategoryValues("1", "10");
}

关于javascript - amchart柱形图上的zoomToCategory,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12250402/

10-10 02:06