首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >highcharts配置

highcharts配置
EN

Stack Overflow用户
提问于 2012-12-14 16:05:37
回答 2查看 348关注 0票数 0

我想用highcharts建立精确的这种类型的图表。

请点击链接- like this graph

我已经构建了一些东西-- mygraph

但我需要用不同的颜色填充整个列,x轴标签将在悬停时显示。

代码语言:javascript
复制
$(function() {
  var chart = new Highcharts.Chart({
    chart: {
      renderTo: 'container',
      type: 'column',
      height: 400,
    },
    plotOptions: {
      column: {
        stacking: 'normal'
      }
    },
    tooltip: {
      //xDateFormat: '%Y-%m-%d',
      formatter: function() {
        return "Click to see all coverage from - " + Highcharts.dateFormat("%b %d", this.x)
      },
      positioner: function(boxWidth, boxHeight, point) {
        return {
          x: point.plotX,
          y: point.plotY
        };
      },
    },
    xAxis: {
      gridLineWidth: 0,
      type: 'datetime',
      dateTimeLabelFormats: {
        day: ' %b %e, %Y'
      }
    },
    yAxis: {
      gridLineWidth: 1,
      title: {
        text: ''
      },
      labels: {
        enabled: true
      }
    },
    legend: {
      enabled: false
    },

    series: [{
      data: [50, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
      pointStart: Date.UTC(2010, 0, 1),
      pointInterval: 24 * 3600 * 1000 // one day
    }],

  });
});
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px; width: 500px"></div>

EN

回答 2

Stack Overflow用户

发布于 2013-03-03 01:14:40

您希望禁用x轴标签并更改系列颜色。

可以通过以下方式禁用X轴值

代码语言:javascript
复制
xAxis: {
    labels: {
              enabled:false
            }
        }

在Highcharts中有超过1种设置颜色的方法。一种方法是按顺序指定颜色。

代码语言:javascript
复制
   series: [{
        data: [50, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
        pointStart: Date.UTC(2010, 0, 1),
        pointInterval: 24 * 3600 * 1000 ,// one day,
        color:"#33333"
    }]

JSFiddle Demo

票数 1
EN

Stack Overflow用户

发布于 2015-02-05 00:30:40

只是为了好玩,原因是和旧的主题,但有趣。

第一种选择可能是创建一个堆叠柱状图,并禁用其中一个系列的工具提示...不是很好的一个,哈哈(请不要这样做)。一个更好的解决方案和足够接近的方法是为每个点创建plotLines。

第一个问题是我们需要创建和列一样多的plotLines。因此,我们将在呈现图表并检查序列数据长度之后执行此操作,而不是在options中执行此操作。

代码语言:javascript
复制
chart.series[0].data.length

第二个问题是,我们必须设置plotLine宽度,所以我们应该在设置列的点宽度之前检查,以便将plotLine宽度设置为等于我们的列。

代码语言:javascript
复制
var plotWidth = chart.series[0].points[0].pointWidth;

第三个问题是我们的图表是固定的,这没问题,但是如果我们的容器是响应式的,我们的图表和列的宽度将会改变,但是我们的plotLines的宽度不会改变,所以我们可以将你的列的宽度和我们的plotLines设置为一个固定值,或者,更好的是,在窗口调整事件时改变我们的plotLines宽度。如果我们对所有的图都使用相同的id (我知道这是错误的,但它是有效的),我们不需要遍历数组,我们可以在一行中删除所有的图。

代码语言:javascript
复制
chart.xAxis[0].removePlotLine('plot-line');

一段重要的代码:

代码语言:javascript
复制
// add plotLines
function addPlotLines(chart, plotWidth) {           
    for(var i = 0; i<= chart.series[0].data.length; i++) {            
        chart.xAxis[0].addPlotLine({
                    color: 'rgba(124, 181, 236,.3)',
                    width: plotWidth,
                    value: Date.UTC(2010, 0, i),
                    dashStyle: 'solid',
                    id: 'plot-line' 
        });
    }
}

// remove PlotLines
function removePlotLines(chart) {
    chart.xAxis[0].removePlotLine('plot-line');
}

// add event resize
window.onresize = function() {
  removePlotLines(chart);
  var plotWidth = chart.series[0].points[0].pointWidth;
  addPlotLines(chart, plotWidth);
};

// initialize
var plotWidth = chart.series[0].points[0].pointWidth;
addPlotLines(chart, plotWidth);

开始吧,完整的代码和演示,请访问http://jsfiddle.net/wbsCu/14/

看看这里没有介绍的show-label-on-point-hover问题。Bold X-Axis Label on Point Hover in Highcharts Column Chart

玩得开心!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13874797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档