簡體   English   中英

帶有類別不起作用的折線圖

[英]Flot line chart with categories not working

我有一個帶有以下代碼的浮動圖表:

var options = {
        lines: {
            show: true
        },
        points: {
            show: true
        },
        xaxis: {
            tickSize: 1,
            mode: "categories"
        }
    };

    var data = [];
    data.push(
        {"label": "Agrobiodiversity for consumption",
    "data": [["January", 3.0], ["February", 3.9], ["March", 2.0], ["April", 1.2], ["May", 1.3], ["June", 2.5],
             ["July", 2.0], ["August", 3.1], ["September", 2.9], ["October", 0.9],["November", 0.5],["December", 1.8]]});

    $.plot($("#flot-dashboard-chart"), data, options);

但是我得到: 在此處輸入圖片說明

我嘗試在軸選項中添加類別,但似乎無濟於事。

知道我還需要添加什么或需要更正什么嗎?

您可以使用我的高位圖表,也可以刪除不必要的內容。

jsFiddle演示

    var chart = Highcharts.chart('container', {
  chart: {
    type: 'bar'
  },
  title: {
    text: ''
  },
  subtitle: {
    text: ''
  },
  xAxis: {
    labels: {
      formatter: function() {
        var link_array = ["first", "second", "third", "fourth"];
        i = 0;
        if (this.value == 'Sugammadex and related compounds')
          return '<a href="#' + link_array[0] + '">' + this.value + '</a>';

        if (this.value == 'Cyclodextrin enabled diclofenac injection (generic Dyloject)')
          return '<a href="#' + link_array[1] + '">' + this.value + '</a>';

        if (this.value == 'Cyclodextrins in biological products')
          return '<a href="#' + link_array[2] + '">' + this.value + '</a>';

        if (this.value == 'Cyclodextrins as a new class of antibiotics')
          return '<a href="#' + link_array[3] + '">' + this.value + '</a>';
      },
      useHTML: true
    },
    categories: ['Sugammadex and related compounds',
      'Cyclodextrin enabled diclofenac injection (generic Dyloject)', 'Cyclodextrins in biological products',
      'Cyclodextrins as a new class of antibiotics'
    ],

    title: {
      text: null
    }
  },
  yAxis: {
    labels: {
      formatter: function() {
        var x_text = ["", "Feasibility study", "Lead / formulation Optimization", "Product Development", "Final product"];

        return x_text[this.value];
      }
    },

    title: {
      text: '',
      align: 'high'
    },

    tickInterval: 1
  },
  tooltip: {
    formatter: function() {
      var x_text = ["", "Feasibility study", "Lead / formulation Optimization", "Product Development", "Final product"];
      return x_text[this.y];
    }
  },

  plotOptions: {

    bar: {
      dataLabels: {
        enabled: false
      }
    }
  },
  credits: {
    enabled: false
  },
  series: [{
    showInLegend: false,
    data: [1, 2, 3, 4]
  }]
});

$(document).ready(function() {
  $("a").on('click', function(event) {
    if (this.hash !== "") {
      event.preventDefault();

      var hash = this.hash;

      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 800, function() {
        window.location.hash = hash;
      });
    }
  });
});

好吧,“類別”模式是一個需要在HTML中加載的插件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM