负轴值使图表出现故障

时间:2018-12-20 17:16:40

标签: javascript highcharts jsfiddle

考虑到提供的数据,我试图创建一些轴上的值被按预期列出的图表(标有红色) enter image description here

但是让我感到困惑的是当我提供负值(刚刚添加的相同值-)时 它只在轴上显示0 enter image description here

是否有可能在提供正值时创建与正值相同的行为,因此提供值时不会出现小故障?

$(function() {
  var chart = new Highcharts.Chart(


  {
  "meta": {
    "drilldownEnabled": false
  },
  "chart": {
  renderTo:"container",
    "additionalData": {
      "dateTime": false,
      "datetype": "string",
      "cliccable": true,
      "drillable": false,
      "drillableChart": false,
      "isCockpit": true,
      "categoryColumn": "product_name",
      "categoryGroupBy": "",
      "categoryGroupByNamens": "",
      "categoryName": "product_name",
      "categoryOrderColumn": "",
      "categoryOrderType": "",
      "categoryStacked": "",
      "categoryStackedType": ""
    },
    "zoomType": "xy",
    "panning": true,
    "type": "column",
    "options3d": {
      "enabled": false,
      "alpha": 25,
      "beta": 15,
      "depth": 50,
      "viewDistance": 25
    },
    "backgroundColor": "#FFFFFF",
    "heightDimType": "pixels",
    "widthDimType": "pixels",
    "plotBackgroundColor": null,
    "plotBorderWidth": null,
    "plotShadow": false,
    "borderColor": "#FFFFFF",
    "style": {
      "backgroundColor": "#FFFFFF",
      "fontFamily": "",
      "fontWeight": "",
      "fontSize": ""
    },
    "events": {}
  },
  "colors": [
    "#7cb5ec",
    "#434348",
    "#90ed7d",
    "#f7a35c",
    "#8085e9",
    "#f15c80",
    "#e4d354",
    "#2b908f",
    "#f45b5b",
    "#91e8e1"
  ],
  "title": {
    "text": "",
    "style": {
      "align": "",
      "color": "",
      "fontFamily": "",
      "fontSize": "",
      "fontWeight": ""
    }
  },
  "legend": {
    "itemDistance": 0,
    "symbolPadding": 25,
    "enabled": false
  },
  "xAxis": [
    {
      "plotBands": [
        {
          "label": {
            "text": "",
            "align": "center"
          },
          "color": "",
          "from": 0,
          "to": 0
        }
      ],
      "plotLines": [
        {
          "label": {
            "text": "",
            "align": "center"
          },
          "color": "",
          "dashStyle": "",
          "value": 0,
          "width": 0
        }
      ],
      "type": "category",
      "id": 0,
      "title": {
        "customTitle": false,
        "text": "product_name",
        "style": {}
      },
      "labels": {
        "style": {
          "color": "",
          "fontFamily": "",
          "fontSize": "",
          "fontWeight": ""
        },
        "align": ""
      }
    }
  ],
  "yAxis": [
    {
      "plotBands": [
        {
          "label": {
            "text": "",
            "align": "center"
          },
          "color": "",
          "from": 0,
          "to": 0
        }
      ],
      "plotLines": [
        {
          "label": {
            "text": "",
            "align": "center"
          },
          "color": "",
          "dashStyle": "",
          "value": 0,
          "width": 0
        }
      ],
      "min": 0,
      "title": {
        "text": "store_sales",
        "customTitle": false,
        "style": {
          "color": "",
          "fontFamily": "",
          "fontWeight": "",
          "fontSize": ""
        }
      },
      "labels": {
        "style": {
          "color": "",
          "fontFamily": "",
          "fontSize": "",
          "fontWeight": ""
        },
        "align": ""
      },
      "gridLineDashStyle": "$convertedTypeline",
      "minorGridLineDashStyle": "$convertedMinorTpeline"
    }
  ],
  "series": [
    {
      "name": "store_sales",
      "dataLabels": {
        "style": {
          "color": "",
          "fontFamily": "",
          "fontWeight": "",
          "fontSize": "",
          "fontStyle": ""
        },
        "enabled": true,
        "labelFormat": "{y:,.2f}"
      },
      "data": [
        {
          "drilldown": false,
          "y": -6.36,
          "name": "ADJ Rosy Sunglasses",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -9.55,
          "name": "Akron City Map",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -12.55,
          "name": "American Beef Bologna",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -7.35,
          "name": "American Chicken Hot Dogs",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -12.19,
          "name": "American Cole Slaw",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -6.68,
          "name": "American Corned Beef",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -8.57,
          "name": "American Foot-Long Hot Dogs",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -6,
          "name": "American Low Fat Bologna",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -7.94,
          "name": "American Low Fat Cole Slaw",
          "datetype": "string"
        },
        {
          "drilldown": false,
          "y": -6.49,
          "name": "American Pimento Loaf",
          "datetype": "string"
        }
      ],
      "selected": true,
      "tooltip": {
        "valueDecimals": 2,
        "scaleFactor": "empty",
        "ttBackColor": "#FCFFC5"
      },
      "yAxis": 0
    }
  ],
  "tooltip": {
    "borderWidth": 0,
    "borderRadius": 0,
    "followTouchMove": false,
    "followPointer": true,
    "useHTML": true,
    "backgroundColor": null,
    "style": {
      "padding": 0
    }
  },
  "lang": {
    "noData": ""
  },
  "noData": {
    "style": {
      "fontFamily": "",
      "fontSize": "",
      "color": ""
    },
    "position": {
      "align": "center",
      "verticalAlign": "middle"
    }
  },
  "credits": {
    "enabled": false
  },
  "plotOptions": {
    "line": {
      "marker": {
        "symbol": "circle",
        "lineWidth": 2
      }
    },
    "series": {
      "events": {},
      "showCheckbox": true,
      "cursor": "pointer",
      "point": {
        "events": {}
      },
      "dataLabels": {
        "allowOverlap": true
      },
      "turboThreshold": 2000
    }
  }
}





  );
});

这是一小段负数(带有毛刺) http://jsfiddle.net/JeLrb/532 这是相同的代码段,只是带有正数(应如何显示轴值) http://jsfiddle.net/JeLrb/533/

有人知道解决方案吗? 谢谢!

2 个答案:

答案 0 :(得分:1)

如果将"yAxis": "min":的值从0更改为-20,它将起作用。

答案 1 :(得分:1)

删除yAxis:“ min:0”,它将为您创建负的yAxis DataLabels。 请检查

 "yAxis": [
{
  /*"min": 0,  remove this */
  "title": {
    "text": "store_sales",
    "customTitle": false,
    "style": {
      "color": "",
      "fontFamily": "",
      "fontWeight": "",
      "fontSize": ""
    }
  }
}

]

http://jsfiddle.net/98b0dkLj