【问题标题】:Make categories on Highcharts stay在 Highcharts 上进行分类
【发布时间】:2015-12-25 04:55:31
【问题描述】:

每次我将数据放入我的 Highcharts 图表时,x 和 y 轴上的类别都是动态的,并且会根据数据进行调整。我希望类别保持不变,我希望:类别:['1', '10', '100', '1000', '10000'] 沿两个轴。

有没有人知道如何让它们保持不变而不管输入的数据如何?

这是我的图表,但我希望底部和左侧的数字显示 1、10、100、1000、1000'

代码:

<script type="text/javascript">
         $(function () {


         function newRandomColor() {
         var color = [];
         color.push((Math.random() * 255).toFixed());
         color.push((Math.random() * 255).toFixed());
         color.push((Math.random() * 255).toFixed());
         color.push((Math.random()).toFixed(2));
         var text = 'rgba(' + color.join(',') + ')';
         console.log(text);
         return text;
         }

         function newRandomData(n) {
         // generate an array of random data
         var data = [],
            time = (new Date()).getTime(),
            i;

         for (i = -1 * n; i <= 0; i++) {
            var color = newRandomColor();
            data.push({
                y:Math.random() * 90 + 60,
                color: color,
                fillColor: color
                      });
         }
         return data;

         }



                 $('#chart5').highcharts({
                     chart: {
                         type: 'scatter',
                         marginRight: 130,
                         marginBottom: 35
                     },
                     title: {
                         text: 'Average vs Max Alarm Rates',
                         x: -20 //center
                     },

                     subtitle: {
                         text: '',
                         x: -20
                     },

                     xAxis: {

                         title: {
                             text: 'Peak alarm rate/10 mins'
                         },
                         plotLines: [{
                             value: 0,
                             width: 1,
                             color: '#b51f2b'
                         }]
                     },
                     yAxis: {

                         title: {
                             text: 'Average alarm rate/10 mins'
                         },
                         plotLines: [{
                             value: 0,
                             width: 1,
                             color: '#b51f2b'
                         }]
                     },
                     tooltip: {
                         valueSuffix: ' alarms'
                     },
                     legend: {
                         layout: 'vertical',
                         align: 'right',
                         verticalAlign: 'top',
                         x: -10,
                         y: 100,
                         borderWidth: 0
                     },
                     series: [{
          color: 'green',
                         name: 'Alarms',

            data: newRandomData(40)

                     }]

                 }, function(chart) { // on complete

         chart.renderer.image('images/alarmrategrid.png', 57, 41, 635, 248)
         .add();   

         });
         });



      </script>

我尝试添加类别,但似乎不起作用。

【问题讨论】:

  • 你能显示图表的代码吗?通常您可以自定义沿每个轴的类别。
  • @SoftwareGuy 已经完成了,干杯:)
  • 好吧,您可能知道这一点,但您使用的是散点图,它没有可用的类别选项。请参阅:highcharts.com/demo/scatter - 如果适用,可以尝试其他图表类型?
  • 另外,考虑看看这个:stackoverflow.com/questions/16451582/…

标签: javascript html charts highcharts


【解决方案1】:
【解决方案2】:

您可以为每个轴设置最小值和最大值:

http://jsfiddle.net/JVNjs/314/

 categories: ['1', '10', '100', '1000', '10000'],
        min:0,
        max:4,
        tickmarkPlacement:'on',

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 2015-01-31
    • 2021-10-02
    • 2020-11-07
    • 2020-07-07
    • 1970-01-01
    相关资源
    最近更新 更多