SVG线未显示在Google图表上?

普里亚

我正在尝试在Google折线图的顶部添加一条线。

我正在使用svg转换线。如果我不使用google.load('visualization', '1', {packages: ['corechart'], callback: drawChart});画线,则移动的垂直线正在工作,但是如果我画图表,则不会显示垂直线。

以下是我在Google折线图上绘制垂直移动线的代码。

 <!DOCTYPE html>
 <html>
<head>
    <script type="text/javascript" src="http://www.google.com/jsapi?.js"></script>  
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
    <script type="text/javascript" src="underscore.js"></script>
    <style>
        .selection_line
        {
            stroke: rgba(0, 0, 0, 0.6);
            shape-rendering: crispEdges;
        }
    </style>
    <script type="text/javascript">
        $(function() {
            // Handler for .ready() called.
            var graph = d3.select('#graph')
                    .append('svg')
                    .attr('width', '100%')
                    .attr('height', 600);


            var line = graph.append('line')
                    .attr('transform', 'translate(0, 50)')
                    .attr({'x1': 0, 'y1': 0, 'x2': 0, 'y2': 300})
                    .attr('class', 'selection_line');

            var x = 0;

            graph.on('mousemove', function() {
                x = d3.mouse(this)[0];
            });

            var draw = function() {
                line
                        .transition()
                        .duration(18)
                        .attrTween('transform', d3.tween('translate(' + x + ', 50)', d3.interpolateString))
                        .each('end', draw);
            };


            draw();
            google.load('visualization', '1', {packages: ['corechart'], callback: drawChart});

        });

        function drawChart() {
            // Create and populate the data table.
            var data = new google.visualization.DataTable();
            data.addColumn('number', 'x');
            // add an "annotation" role column to the domain column
            data.addColumn({type: 'string', role: 'annotation'});
            data.addColumn('number', 'y');

            // add 100 rows of pseudorandom data
            var y = 50;
            for (var i = 0; i < 100; i++) {
                y += Math.floor(Math.random() * 5) * Math.pow(-1, Math.floor(Math.random() * 2));
                data.addRow([i, null, y]);
            }
            // add a blank row to the end of the DataTable to hold the annotations
            data.addRow([null, null, null]);
            // get the index of the row used for the annotations
            var annotationRowIndex = data.getNumberOfRows() - 1;

            var options = {
                height: 400,
                width: 600
            };

            // create the chart
            var chart = new google.visualization.LineChart(document.getElementById('graph'));


            // draw the chart
            chart.draw(data, options);

        }

    </script>
</head>
<body>
    <div id="graph"></div>
</body>

拉尔斯·科特霍夫(Lars Kotthoff)

为此,您必须在由Google图表生成的SVG上添加一行,并根据鼠标指针的位置移动它,而忽略x组件:

var line = graph.append('line')
                .attr('transform', 'translate(100, 50)')
                .attr({'x1': 0, 'y1': 0, 'x2': 400, 'y2': 0})
                .attr('class', 'selection_line');

graph.on('mousemove', function() {
            line.attr("y1", d3.event.y - 50);
            line.attr("y2", d3.event.y - 50);
        });

这里完整的例子

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

SVG线未显示在Google图表上?

来自分类Dev

Google图表趋势线未显示

来自分类Dev

Google图表未显示在iOS设备上

来自分类Dev

Google材料图表(散点图)未显示趋势线或工具提示

来自分类Dev

Google图表未显示

来自分类Dev

多系列d3 svg图表未显示刻度线

来自分类Dev

在scrollTop()上显示Google图表

来自分类Dev

动画 matplotlib 图形上的线未显示

来自分类Dev

数据未显示在Google图表中

来自分类Dev

未显示Google Analytic Embed API图表

来自分类Dev

数据未显示在Google图表中

来自分类Dev

Google图表未显示,未显示任何错误

来自分类Dev

Google图表:工具提示中的图表未显示

来自分类Dev

图表上的十字线显示

来自分类Dev

react-google-charts 未显示在 ie11 上-“无法绘制图表数据”

来自分类Dev

由于svg,图表圆圈未显示在小提琴中

来自分类Dev

由于svg,图表圆圈未显示在小提琴中

来自分类Dev

Google图表在yAxis上持续显示负值

来自分类Dev

在Google图表上取消显示空值

来自分类Dev

Google图表在yAxis上持续显示负值

来自分类Dev

SVG(icomoon)未显示在Firefox上

来自分类Dev

文本元素未显示在SVG上

来自分类Dev

R在图表上的多条线

来自分类Dev

线未在图表上绘制

来自分类Dev

extjs图表未显示

来自分类Dev

图表未显示

来自分类Dev

图表未显示

来自分类Dev

JQPlot图表未显示

来自分类Dev

我的JavaFX工具提示未显示在图表数据节点上