为什么X轴每月出备用数月而不是?

问题描述 投票:0回答:1

以下是我的highcharts配置,你可以帮我为什么我的备用月来了,如果我想每个月显示,我该怎么做呢?此外,如果要显示每个月改变吧的宽度。

Highcharts.chart("energy_chart", {
            chart: {
              type: "column",
              spacingBottom: 15,
              spacingTop: 10,
              spacingLeft: 10,
              spacingRight: 10,
              backgroundColor: "#f2f2f2",
              events: {
                load: function() {
                  var fin = new Date();
                  var finDate = fin.getDate();

                  var finMonth = fin.getMonth();
                  var finYear = fin.getFullYear();

                  var ini = new Date();
                  ini.setFullYear(ini.getFullYear() - 1);
                  var iniDate = ini.getDate();
                  var iniMonth = ini.getMonth();
                  var iniYear = ini.getFullYear();
                  if (this.yAxis[0].dataMax == 0) {
                    this.yAxis[0].setExtremes(null, 1);
                  }
                  //this.yAxis.set
                  console.log(new Date(Date.UTC(iniYear, iniMonth, iniDate)))
                  console.log(new Date(Date.UTC(finYear, finMonth, finDate)))
                  this.xAxis[0].setExtremes(
                    Date.UTC(iniYear, iniMonth, iniDate),
                    Date.UTC(finYear, finMonth, finDate)
                  );
                },

                drilldown: function(e) {
                  console.log('drilldown')
                  var charts_this = this;
                  var inidrillDate = new Date(e.point.x);

                  setTimeout(function() {
                    inidrillDate.setDate(0);
                    inidrillDate.setMonth(inidrillDate.getMonth());
                    var DateinidrillDate = inidrillDate.getDate();
                    var MonthinidrillDate = inidrillDate.getMonth();
                    var YearinidrillDate = inidrillDate.getFullYear();
                    var findrillDate = inidrillDate;
                    findrillDate.setMonth(findrillDate.getMonth() + 1);
                    findrillDate.setDate(findrillDate.getDate() - 1);
                    var DatefindrillDate = findrillDate.getDate();
                    var MonthfindrillDate = findrillDate.getMonth();
                    var YearfindrillDate = findrillDate.getFullYear();
                    console.log(Date.UTC(
                      YearinidrillDate,
                      MonthinidrillDate,
                      DateinidrillDate
                    ))
                    console.log(Date.UTC(
                      YearfindrillDate,
                      MonthfindrillDate,
                      DatefindrillDate
                    ))
                    charts_this.xAxis[0].setExtremes(
                      Date.UTC(
                        YearinidrillDate,
                        MonthinidrillDate,
                        DateinidrillDate
                      ),
                      Date.UTC(
                        YearfindrillDate,
                        MonthfindrillDate,
                        DatefindrillDate
                      )
                    );

                    if (charts_this.yAxis[0].dataMax === 0) {
                      charts_this.yAxis[0].setExtremes(null, 1);
                    }
                  }, 0);

                }
              }
            },
            title: {
              text: '<p className="energy_gen">Energy Generated</p>'
            },
            exporting: { enabled: false },
            xAxis: {
              type: "datetime",
              labels: {
                step: 1
              },
              dateTimeLabelFormats: {
                day: "%e"
              }
            },
            yAxis: {
              title: {
                text: "kWh"
              }
            },
            credits: {
              enabled: false
            },
            plotOptions: {
              series: {
                cursor: "pointer",
                dataLabels: {
                  enabled: true,
                  format: "{point.y}"
                },
                color: "#fcd562",
                point:{
                  events:{
                    click:function(event){
                      }     
                    }
                  }
                }
              }
            },
            tooltip: {
              formatter: function() {
                if (this.point.options.drilldown) {
                  return (
                    "Energy generated: <b> " +
                    this.y +
                    "</b> kWh " +
                    "<br>" +
                    Highcharts.dateFormat("%b %Y", new Date(this.x))
                  );
                } else {
                  return (
                    "Energy generated: <b> " +
                    this.y +
                    "</b> kWh " +
                    "<br>" +
                    Highcharts.dateFormat("%e %b %Y", new Date(this.x))
                  );
                }
              }
            },
            series: [{'data':obj.data,'name':obj.name,"color":"#4848d3"}],
            drilldown: {
              series: obj.data
            }
          });

另外,附接与钻取渲染highchart的屏幕截图。

graph1

现在,向下钻取图表(同不大不小的问题)

drilldown graph

编辑:

它原来是一个放大的问题,即如果我够缩小(ZoomOut),那么它会显示所有点。那么,如何显示没有缩小的每一个点。

工作小提琴:

http://jsfiddle.net/gkumar77/w9ngp63u/5/

highcharts
1个回答
1
投票

使用tickInterval属性并将其设置为一个月:

        xAxis: {
          type: "datetime",
          tickInterval: 30 * 24 * 3600 * 1000,
          labels: {
            step: 1
          },
          dateTimeLabelFormats: {
            day: "%e"
          }
        }

现场演示:http://jsfiddle.net/BlackLabel/q5coany2/

API:https://api.highcharts.com/highcharts/xAxis.tickInterval

© www.soinside.com 2019 - 2024. All rights reserved.