几个月之间需要完整的图表

时间:2019-07-19 06:27:34

标签: javascript jquery graph charts highcharts

我已经创建了高图来完全满足我的要求,如所附图像所示,并且我尝试了以下小提琴中的代码 小提琴中的示例代码如下

https://jsfiddle.net/vsLr07ak/

下面是我的代码

   Highcharts.chart('container', {
 chart: {
    type: 'column'
 },
 title: {
    text: 'HISTORICAL NEWS SENTIMENT'
 },
  yAxis: {
    title: {
        text: ''
    },
     labels: {
            enabled: false
        },
    min: -100,
    max: 100,
    tickInterval: 10,
    showLastdataLabel: true,
  },
  xAxis: {
    categories: ['26. Nov', '24. Dec', '21. Jan', '18. Feb', '18. March']
  },
  credits: {
    enabled: false
  },
  series: [{
    name: null,
    data: [15, 13, 14, 17, 12]

     }, {
    name: null,
    data: [12, -12, -13, 21, 11]
  }]
  });

HTML代码与

  <script src="https://code.highcharts.com/highcharts.js"></script>
  <script src="https://code.highcharts.com/modules/exporting.js">. 
  </script>
  <script src="https://code.highcharts.com/modules/export-data.js"></script>
  <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

但是它每个月显示2条,我希望它显示为以下附件图像。

有人可以帮我吗?

并且我希望我的图表如图chart image

所示

1 个答案:

答案 0 :(得分:0)

您应该使用category xAxis类型而不是datetime并将x的值定义为时间戳:

series: [{
    ...,
    data: [
        [17227780000, 15],
        [18523780000, 13],
        [19819780000, 14],
        [21115780000, 17],
        [22411780000, 12],
        [23707780000, 12],
        [25003780000, -12],
        [26299780000, -13],
        [27595780000, 21],
        [28891780000, 11]
    ]
}]

实时演示: https://jsfiddle.net/BlackLabel/83us07cx/

或使用pointStartpointInterval属性:

series: [{
    pointStart: 17227780000,
    pointInterval: 1000 * 60 * 60 * 24 * 15, // 15 days
    name: null,
    color: 'red',
    negativeColor: 'blue',
    data: [15, 13, 14, 17, 12, 12, -12, -13, 21, 11]
}]

实时演示: https://jsfiddle.net/BlackLabel/sqtha8xm/


API参考:

https://api.highcharts.com/highcharts/series.column.data

https://api.highcharts.com/highcharts/series.column.pointStart

https://api.highcharts.com/highcharts/series.column.pointInterval

https://api.highcharts.com/highcharts/series.column.negativeColor