javascript - 具有双轴断点和拖动点的 Highcharts

标签 javascript jquery charts highcharts

我想制作带有双轴断点的图表并拖动该点,如下图所示。 enter image description here

有人可以告诉我我该怎么做吗? 我探索了 highchart,但找不到合适的选项来创建它。 还有其他选择吗?

var seriesOptions = [],
    names = ['MSFT'];
$(document).ready(function(e) {
     // Start the standard Highcharts setup
    $.each(names, function(i, name) {
        seriesOptions[i] = {
            data: [0,20, 40, 60]
        };
        createChart();
    });
});

// create the chart when all data is loaded
function createChart() {
    $('#container').highcharts('StockChart', {
        chart: {
            backgroundColor: "#40aa98"
        },
        credits: {enabled: false},
        rangeSelector: {enabled: false},
        navigator: { enabled: false},
        scrollbar: {enabled: false},
        yAxis: {
            min:0,
            max:60,
            labels: {
                align: 'right',
                formatter: function() {
                    return  '$' + this.value + 'k';
                },
                x:-5,
                y:-2
            },
            opposite:false,
            gridLineWidth: 0,
            gridZIndex: 0,
            minorGridLineColor: "#fff",
            minorGridLineWidth: 2,
            minorTickColor: "#fff",
            plotLines: [{
                value: 20,
                width:3,
                color: '#fff'
            }]
        },
        xAxis: {
            min:0,
            max:60,
            crosshair: {
                color: '#006753',
                dashStyle: "Solid",
                snap: true,
                width:4,
                zIndex: 2,
            }
        },
        legend: {
            enabled: true,
            floating: true,
            align: 'left',
            verticalAlign: 'top',
            y: 10,
            labelFormat: '<span style="color:#fff">{name}</span>: <b>{point.y:.2f} USD</b> ({point.change:.2f}%)<br/>',
            borderWidth: 0
        },
        plotOptions: {
            series:{
                marker:{
                    enabled: false,
                    fillColor: '#ef188d',
                    width: 20,
                    radius: 10,
                    height: 20,
                    lineColor: "#006753",
                    lineWidth: 2
                   
                },
                
            }
        },
        
        series: seriesOptions
    });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/stock/highstock.src.js"></script>
<script src="https://rawgithub.com/highslide-software/value-in-legend/master/value-in-legend.js"></script>
<div id="container" style="height: 400px; width: 600px; margin:auto"></div>

我尝试了这个,仍然找到了一些帮助。

最佳答案

要绘制合适的背景,您需要使用Renderer并将三 Angular 形宽度渲染为适当的填充。

function drawBackground() {
  var xAxis = this.xAxis[0];
  var yAxis = this.yAxis[0];

  var x1 = this.plotLeft,
    y1 = yAxis.toPixels(20),
    y2 = this.plotTop + this.plotHeight;

  var crossPoint = [xAxis.toPixels(20), y1];

  var pathUnder = this.renderer.path([
    'M', x1, y1,
    'L', crossPoint[0], crossPoint[1],
    'L', x1, y2,
    'Z'
  ]).attr({
    'stroke-width': 0,
    fill: '#145F28'
  }).add();

  var x2 = x1 + this.plotWidth;

  var pathBeyond = this.renderer.path([
    'M', crossPoint[0], y1,
    'L', x2, y1,
    'L', x2, this.plotTop,
    'Z'
  ]).attr({
    'stroke-width': 0,
    fill: '#64EF88'
  }).add();
}

在加载时设置绘图函数:

chart: {
  backgroundColor: "#40aa98",
  events: {
    load: drawBackground
  }
},

示例:https://jsfiddle.net/ec4ddj24/

关于javascript - 具有双轴断点和拖动点的 Highcharts ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41929960/

相关文章:

javascript - 数组过滤器未返回正确的值

javascript - Google 图表平移缩放按钮

c# - ASP.NET 图表控件的默认 3D 图表透明度?

javascript - 我应该为我的 PhoneGap 应用缩小和合并 JS 文件吗?

javascript - 如何实例化要在单元测试中使用的 Sequelize 模型?

javascript - 在 Node.js (Javascript) 中将十六进制转换为文本 (ASCII) 或 JSON 对象

javascript - 第一次单击后禁用提交按钮

javascript - 仅使用 JS 控制台刷新元素

jquery - 添加到表格时淡入表格行

javascript - 如何从 Highcharts 区域类别图表的两侧删除填充?