单轴的静态(无滑块)图表(Google图表或其他)?

时间:2012-11-12 20:04:58

标签: javascript graph charts google-visualization data-visualization

我需要将一系列值显示为类似下图的图表:

chart with single axis

这个想法是有最小值和最大值。我试图展示的价值可能介于两者之间。

我打算使用谷歌图表,他们的Bar Chart (Image)几乎是我想要的,但按轴显示xy我似乎只想要x,或者y。 (用已故马克·朝圣者的话说,“我不是很好地解释这一点。”)

任何人都可以通过此Google条形图(或其他Google图表)或其他内容向我展示如何执行此操作吗?

1 个答案:

答案 0 :(得分:0)

以下是我提出的内容(使用条形图图像 - 如上所述 - 来自Google Charts API,但不使用图表中的标签):

<script type="text/javascript">
    google.load("visualization", "1", {packages:["imagebarchart"]});
    google.setOnLoadCallback(drawChart);
    function drawChart() {

        //Here we display a range from 10 million (10000000)
        //to 20 million (20000000), using a dummy value set
        //to 1 less than the low point of our range (in this
        //case, 9999999) and with the same color as the
        //chart's background. The dummy value will be stacked
        //on top of the value we want to show and blank out
        //the chart from 0 to where our range begins.

        var data = google.visualization.arrayToDataTable([
            ['', ''],
            [9999999, 20000000]
        ]);

        var chart = new google.visualization.ImageBarChart(document.getElementById("chart_div"));
        chart.draw(data, {showValueLabels: false, backgroundColor: '#f5f5f5',  width: 1000, height: 70, min: 100000, max: 50000000, colors: ['#f5f5f5', '#008000']});
    }
</script>

chart_div是页面加载时由图表替换的div;此代码基于the chart docs中的示例。)

显然,这个特殊的条形图并不是以这种方式使用,但它是我能找到的最接近我想要的。我希望这可以帮助有同样问题的人。