【问题标题】:HighCharts plugin JQueryHighCharts 插件 JQuery
【发布时间】:2013-10-28 10:11:06
【问题描述】:

我使用 HighCharts 插件来绘制图表。但我有一些麻烦:当图表为空时,我只看到 xAxis,而 yAxis 不显示。当图表不为空且有绘制图表的数据时,显示y轴。我找不到解决这个问题的方法。

function drawChart(jsonData) {
    var rate = 20;
    var is3Axis = $("#sel_charttype").val() == "1";

    var options = {
        chart: {
            renderTo: 'chart',
            defaultSeriesType: 'line',
            margin: [50, 65, 50, 55],
            backgroundColor: '#fff'
        },
        title: null,
        xAxis: {
            categories: jsonData.timeTicks
        },
        tooltip: {
            enabled: true,
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                    this.x + ': ' + this.y;
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true,
                    style: {
                        fontSize: '13px'
                    },
                    x: 0,
                    y: -10
                },
                marker: {
                    symbol: 'circle'
                }
            }
        },
        legend: {
            layout: 'horizontal',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 0,
            floating: false,
            shadow: false,
            borderWidth: 0,
            itemStyle: {
                fontSize: '11px'
            }
        },
        credits: {
            enabled: false
        }
    };

    if (is3Axis) {
        options.yAxis = [
            //primary axis
            {
                title: {
                    text: 'Amount'
                },
                gridLineColor: '#f1f1f1'
            },
            {
                gridLineWidth: 0,
                title: {
                    text: 'Total',
                    style: {
                        //color: '#89A54E'
                    }
                },
                opposite: true
            }
        ];
        options.series = jsonData.summary3AxisData;
    } else {
        // options.chart.margin[1] = 30;
        options.yAxis = {
            title: {
                text: ''
            },
            gridLineColor: '#f1f1f1'
        };
        options.series = jsonData.summaryData;
    }

    if (chart)
        $("#chart").html('');

    chart = new Highcharts.Chart(options);

    if (jsonData.url) {
        $("#chart .highcharts-container").css("cursor", "pointer").click(function () {
            window.open(jsonData.url, "_self");
        });
    }
}

【问题讨论】:

  • 嗨!请向我们展示您的代码中的几行代码。
  • 是的,完成了!对不起!

标签: javascript jquery highcharts


【解决方案1】:

ShowEmpty 应该可以工作,报告here

解决方法很简单:始终使用至少一个系列,例如设置showInLegend: false,请参阅:http://jsfiddle.net/3UPQF/

请注意,轴的最小值和最大值需要设置。

【讨论】:

    【解决方案2】:

    可以使用showEmpty参数,但如果series为空,默认不显示刻度/标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      相关资源
      最近更新 更多