在Highcharts中使用日期时,如何防止Highcharts显示杂乱的x轴标签?
我正在生成我的图表:
<script type="text/javascript">
$(function () {
$.getJSON("get_data", function(data) {
data.plotOptions = {
line: {
marker: {
enabled: false
}
}
};
data.chart.zoomType = 'x';
data.legend = {
layout: 'vertical',
align: 'center',
verticalAlign: 'top',
x: 10,
y: 100,
borderWidth: 0
};
data.xAxis.type = 'datetime';
data.xAxis.title = {text: 'Date'};
$('#container').highcharts(data);
});
});
</script>
并且get_data
路径返回的JSON如下所示:
{"yAxis": {}, "title": {"style": {}, "text": null}, "series": [{"name": "Apple", "data": [1.0, -3.0, 1.0, 4.0, -5.0, 4.0, -1.0, 4.0, 2.0, -1.7741935483871, 3.0, -5.0, 3.0, 2.0, 0.0, -3.0, 1.0, -2.0, 2.0, 4.0, 1.0, -5.0, 5.0, -4.0, 0.0, 4.0, 2.0, -2.0, 0.0, 1.0, -2.0, 4.0, 0.0, -5.0, -5.0, 0.0, -5.0, 3.0, -1.0, 1.0, 4.0, 2.0, -5.0, 4.0, 0.0, 2.0, 1.0, -3.0, 5.0, -1.0, 5.0, -2.0, -4.0, 4.0, -0.324324324324324, -1.0, 3.0, -1.0, 3.0, -3.0, 5.0, 4.0, -3.0, 0.0, 4.0, 0.0, -1.678456591639871, 4.324675324675325, 4.436681222707424, 5.291545189504373, -4.0, -1.0, 3.272479564032698, 3.0, -0.738219895287958, -5.0, -3.0, 4.0, 2.0, -0.719101123595506, -5.0, 5.0, -3.202127659574468, 4.0, 1.3597122302158269, -3.74055415617128, 1.32450331125828, 1.33003300330033, -2.358974358974359, 4.0, 3.0, 4.25391849529781, 4.02564102564103, -0.49622166246851396, 0.86335403726708, 0.628930817610063, -2.89227166276347, 0.08641975308642014, 6.09597523219814, 4.5294117647058805, 1.7272727272727302, 4.406326034063261, -1.2431077694235602, 2.49019607843137, 3.2, 6.06060606060606, 4.75, 7.66830466830467, 8.0952380952381, 12.07692307692308, 3.10628019323671, 8.24242424242424, 2.5853658536585398, 8.006006006006011, -1.9969969969969998, 7.571428571428569, 3.70570570570571, 3.37017994858612, 7.75229357798165, 9.01567398119122, 6.10772833723653, 4.84615384615385, 0.7151702786377698, -1.25, 4.73186119873817, 6.68098159509202, 3.50877192982456, 5.147699757869249, 6.68098159509202, 8.64077669902913, 3.71517027863777, -1.3414634146341502, 5.53012048192771, 9.08805031446541, 8.146341463414629, 2.7021943573667704, 7.77777777777778, 7.703703703703701, 5.97628458498024, 3.3824701195219102, 4.6, 10.11620795107034, 5.60663507109005, 5.21674876847291, 8.96341463414634, -2.5, 6.05882352941176, -1.2392638036809802, 1.8679706601466997, 11.306306306306311, 1.0752351097178696, 0.8929440389294401, 9.4380664652568, 5.10059171597633, 11.33333333333333, 9.882352941176471, 5.10059171597633, 1.9069069069069098, 6.69607843137255, 5.56716417910448, 3.05952380952381, 9.918032786885249, 6.51807228915663, 5.43137254901961, 6.42477876106195, 9.68384074941452, 2.98507462686567, 7.43786982248521, 7.25581395348837, 0.9215686274509798, 9.65116279069767, 2.1515151515151496, 7.71698113207547, 2.82352941176471, -1.1896955503512898, -0.48093841642229007, 4.71976401179941, 6.94117647058824, 10.56844547563805, 3.95626822157434, 6.6379821958457, 2.31400966183575, 7.33734939759036, 8.48837209302326, 6.62060889929742, 5.76368876080692, 10.341246290801191, 5.43735224586288, 3.5527065527065496, 1.4631828978622297, 2.25075528700906, 8.7463556851312, 8.84955752212389, 3.5268065268065296, 6.720823798627, 4.94296577946768, 3.08083140877598, 8.88235294117647, 2.89473684210526, 2.55555555555556, 8.7246376811594, 1.9767441860465098, 15.7558139534884, 10.64705882352941, 8.3053435114504, 5.48854961832061, 8.142857142857139, 2.85480093676815, 10.387205387205391, 9.0, 3.94117647058824], "showInLegend": true}, {"name": "Orange", "data": [2.0, 2.0, 4.0, -4.0, 3.0, -1.0, 0.0, 2.0, 4.0, 3.0, -4.0, 2.0, -2.0, 1.0, 2.0, 3.0, 0.0, -1.0, 0.0, -2.0, 4.0, 1.0, 5.0, 4.0, -1.0, -3.0, -5.0, -3.0, -3.0, 3.0, -2.0, -2.0, 0.0, 3.0, -3.0, -1.0, 0.0, 5.0, 4.0, -3.0, -2.0, 0.0, 0.0, 4.0, 0.0, 0.0, -4.0, 0.0, -3.0, 2.0, -1.0, 4.0, -2.0, -3.0, -5.0, 1.0, -5.0, -1.0, -1.0, 1.0, 1.0, -3.0, 5.0, -4.0, -3.0, -3.0, -4.0, -4.0, -5.0, 1.0, 5.0, 1.0, -1.0, 0.0, 2.0, -2.5555555555555562, -1.0, 0.0, -1.0, 5.0, 5.467289719626168, 0.0, -2.0, 1.0, 1.0, 0.0, -1.0, -2.0, 4.0, 5.0, 3.0, 3.0, -3.0, 5.0, -3.0, 0.0, 1.0, -4.0, -5.0, 1.0, -3.0, 3.0, 5.0, 3.0, 5.0, -5.0, 5.0, 5.0, 0.0, -2.0, -3.0, 4.0, 3.0, -5.0, -5.0, 1.0, 3.0, -4.74293059125964, -5.0, 0.313479623824451, 5.0, 3.0, 4.0, 1.0, -2.0, -1.0, 2.0, -3.757869249394673, 4.0, 5.0, 0.0, 0.48780487804878, 1.0, -4.0, 2.0, 5.0, 4.3086419753086425, 0.0, -5.0, 1.0, 4.0, -3.0, -4.0, 3.0, 1.0, -5.0, 1.0, -1.0, 3.0, -1.0, 3.0, 1.0, 1.0, 4.0, -3.702380952380952, 1.0, 5.0, 0.0, 5.0, -1.0, 3.0, 1.0, -3.0, 1.0, -2.0, 2.234192037470726, -5.0, -2.0, -3.0, -2.0, 2.0, 2.0, 4.0, 1.294117647058824, -5.0, -2.0, 0.0, 5.0, -3.0, 1.0, 4.0, -2.758454106280193, 5.0, 4.0, 4.17096018735363, -3.84726224783862, -3.0, -2.0543735224586293, 4.854700854700855, -1.33729216152019, 0.906344410876133, 3.8746355685131197, 1.17994100294985, 7.29370629370629, 1.03432494279176, 0.8022813688212902, 8.00461893764434, 9.705882352941181, 4.39097744360902, 2.00925925925926, 4.869565217391304, 3.232558139534884, 2.8720930232558137, -2.117647058823529, 2.954198473282443, -2.236641221374046, 1.0, 4.702576112412178, 3.0, 5.680851063829787, -3.0], "showInLegend": true}, {"name": "Pear", "data": [4.0, 1.0, -2.0, 1.0, 1.0, -4.0, -1.0, -5.0, -1.0, 0.0, -2.0, 1.0, 1.0, -2.0, -4.0, -4.0, 3.0, 2.0, -5.0, 1.0, 1.0, -1.0, -4.0, 5.0, -5.0, 0.0, 5.0, 4.0, -2.0, 5.0, -1.0, -2.0, 4.0, -1.0, -5.0, 4.0, -3.0, 4.0, 5.0, 5.0, -1.0, 0.0, 3.0, 3.50375939849624, -2.0, 5.0, -5.0, -5.0, -3.0, 1.0, -4.0, 3.0, -2.0, 2.980392156862745, 5.0, 3.0, 0.0, -4.0, 0.0, -3.0, -2.0, -1.0, 4.0, 5.0, 3.24330900243309, 3.0, 3.643086816720257, -4.675324675324675, 3.31004366812227, -3.7084548104956268, 4.0, 0.51150895140665, 5.544959128065395, -4.553571428571429, 0.0, 5.0, 1.0, 4.248756218905473, 0.0, 4.561797752808989, 3.467289719626168, -1.74025974025974, 3.265957446808511, -2.326599326599327, 3.359712230215827, 2.0, 0.0, 1.33003300330033, -5.0, -1.757281553398058, -4.696048632218845, 4.0, 4.256410256410256, 5.251889168765743, 2.0, 0.628930817610063, -2.0, -0.691358024691358, 0.0, 0.294117647058824, 5.303030303030303, 0.24330900243309, 3.0, 3.0, -1.4, -5.0, -1.583333333333333, -2.017199017199017, 3.297619047619048, 5.0, 3.241545893719807, -5.0, -3.0, -0.6996996996997, -4.0, 4.255102040816327, -2.6996996996997, 2.7712082262210798, -5.0, 2.0, 2.0, -4.408284023668639, -0.690402476780186, -2.75, 3.315457413249211, -0.386503067484663, -3.707602339181287, 2.0, 2.920245398773006, -4.0, -4.0, -0.51219512195122, -1.698795180722892, 3.0, 1.24390243902439, 0.5673981191222599, 2.617283950617284, 0.493827160493827, 2.395256916996047, 2.398406374501992, -3.0, -4.388379204892966, -5.0, 2.246305418719212, 1.6097560975609762, -2.0, 1.0, 2.0, -4.755501222493888, -1.7987987987988, -2.0595611285266457, -0.75669099756691, 1.302114803625378, 2.4792899408283997, -5.0, 0.235294117647059, -2.0, -1.0, 1.0, 0.597014925373134, -3.404761904761905, 1.7025761124121779, -2.0, -3.264705882352941, 3.294985250737463, 5.234192037470726, 2.5970149253731343, 5.29585798816568, -1.767441860465116, 5.0, 5.465116279069767, 0.303030303030303, 4.471698113207547, 4.882352941176471, -3.297423887587822, 0.586510263929619, -1.705014749262537, 0.0, -3.535962877030162, -2.7084548104956268, 4.29673590504451, 2.241545893719807, -4.759036144578313, -4.0, -1.0, 0.5936599423631099, 2.18694362017804, 1.0189125295508301, 4.12820512820513, 6.37529691211401, 2.02114803625378, 3.08163265306122, 7.71976401179941, 8.4219114219114, 17.6453089244851, 3.22433460076046, 17.2401847575058, 15.8235294117647, 16.3007518796992, 19.75, 14.681159420289902, 22.2325581395349, 40.5697674418605, 40.3529411764706, 51.618320610687, 47.6564885496183, 33.7142857142857, 39.0023419203747, 40.026936026936, 26.2127659574468, 24.9019607843137], "showInLegend": true}, {"name": "Banana", "data": [0.0, 2.0, -5.0, 4.0, 0.0, 1.0, -1.0, 5.0, 4.0, 8.2258064516129, 2.0, -5.0, 2.0, 4.0, 3.0, -3.0, -5.0, 7.526315789473699, 5.0, 2.0, 3.0, 3.0, -3.0, 4.0, -1.0, 6.61290322580645, -3.0, 3.0, 5.0, 0.0, -5.0, -3.0, 0.0, 0.0, -5.0, -1.0, -3.0, 3.0, -3.0, 2.0, 4.0, -2.9010989010988997, 3.0, -2.0, 2.0, 3.0, 0.934579439252336, 2.0, -2.0, -5.0, 0.0, 5.0, -1.0, -3.0, -5.0, -1.159663865546218, 4.0, 5.0, -1.3103448275862069, -2.0, -0.25373134328358204, -4.0, 5.0, 4.0, 2.0, 1.0, -0.678456591639871, 5.0, 4.0, -2.7084548104956268, -4.0, 0.255754475703325, 2.272479564032698, -2.553571428571429, 5.261780104712042, -3.0, -4.0, -0.7512437810945269, -0.367088607594937, 2.561797752808989, 5.0, -4.0, -2.0, -2.663299663299663, -0.640287769784173, 2.755667506297229, 1.993377483443709, -1.33993399339934, -1.358974358974359, -2.514563106796116, 1.60790273556231, 5.0, -3.230769230769231, 2.503778337531486, 0.86335403726708, 4.943396226415094, 5.512880562060889, 5.703703703703701, 1.4767801857585101, 5.6470588235294095, -1.5757575757575801, 1.4330900243309, 1.00250626566416, 1.96078431372549, -4.2, 1.51515151515152, 4.25, 3.47420147420147, 2.8928571428571432, 2.0, 0.483091787439614, 4.303030303030303, -2.0, 3.0, 0.3003003003003, 0.53061224489796, -4.099099099099099, 2.51413881748072, -3.694189602446483, 0.940438871473354, -0.06323185011709598, -1.5207100591716, 1.619195046439629, 5.0, 0.946372239747634, -2.386503067484663, 3.0, 5.0, 0.613496932515337, -4.271844660194175, 4.928792569659443, 1.24390243902439, -3.698795180722892, -0.371069182389937, -1.04878048780488, -0.373040752351097, -0.07407407407407396, 1.4938271604938271, -2.604743083003953, -2.800796812749004, -3.2, -3.7767584097859297, -3.052132701421801, 0.492610837438424, 5.304878048780488, 1.3125, 1.470588235294118, 0.920245398773006, 3.488997555012225, -4.399399399399399, 3.626959247648903, -2.75669099756691, 3.7190332326284, -4.0, 4.892857142857143, -0.8235294117647101, 3.4792899408283997, -2.099099099099099, 3.0, -3.0, -2.0, -1.0, -0.39759036144578297, 2.0, 3.294985250737463, -4.297423887587822, 0.597014925373134, 4.887573964497041, 4.465116279069767, -2.607843137254902, 4.930232558139535, 3.606060606060606, 2.0, -4.117647058823529, -2.0, 1.0, 3.589970501474926, 5.0, -2.0, 3.0, 3.0, -0.5507246376811601, -2.34939759036145, 0.6511627906976702, -2.42388758782201, -2.84726224783862, 3.18694362017804, -0.9267139479905402, 7.279202279202281, 8.03800475059382, -2.88519637462236, -0.9591836734693899, 2.65486725663717, 11.09090909090909, 2.32265446224256, 0.7034220532319404, 6.2378752886836, 7.823529411764699, 18.5338345864662, 13.3518518518519, 18.6231884057971, 23.6046511627907, 20.3139534883721, 12.23529411764706, 11.10687022900763, 5.81679389312977, 2.71428571428571, -0.36065573770492, 1.1986531986531999, 1.70212765957447, 3.96078431372549], "showInLegend": true}], "chart": {}, "colorAxis": {}, "xAxis": {"categories": ["2000-01-01", "2000-02-01", "2000-03-01", "2000-04-01", "2000-05-01", "2000-06-01", "2000-07-01", "2000-08-01", "2000-09-01", "2000-10-01", "2000-11-01", "2000-12-01", "2001-01-01", "2001-02-01", "2001-03-01", "2001-04-01", "2001-05-01", "2001-06-01", "2001-07-01", "2001-08-01", "2001-09-01", "2001-10-01", "2001-11-01", "2001-12-01", "2002-01-01", "2002-02-01", "2002-03-01", "2002-04-01", "2002-05-01", "2002-06-01", "2002-07-01", "2002-08-01", "2002-09-01", "2002-10-01", "2002-11-01", "2002-12-01", "2003-01-01", "2003-02-01", "2003-03-01", "2003-04-01", "2003-05-01", "2003-06-01", "2003-07-01", "2003-08-01", "2003-09-01", "2003-10-01", "2003-11-01", "2003-12-01", "2004-01-01", "2004-02-01", "2004-03-01", "2004-04-01", "2004-05-01", "2004-06-01", "2004-07-01", "2004-08-01", "2004-09-01", "2004-10-01", "2004-11-01", "2004-12-01", "2005-01-01", "2005-02-01", "2005-03-01", "2005-04-01", "2005-05-01", "2005-06-01", "2005-07-01", "2005-08-01", "2005-09-01", "2005-10-01", "2005-11-01", "2005-12-01", "2006-01-01", "2006-02-01", "2006-03-01", "2006-04-01", "2006-05-01", "2006-06-01", "2006-07-01", "2006-08-01", "2006-09-01", "2006-10-01", "2006-11-01", "2006-12-01", "2007-01-01", "2007-02-01", "2007-03-01", "2007-04-01", "2007-05-01", "2007-06-01", "2007-07-01", "2007-08-01", "2007-09-01", "2007-10-01", "2007-11-01", "2007-12-01", "2008-01-01", "2008-02-01", "2008-03-01", "2008-04-01", "2008-05-01", "2008-06-01", "2008-07-01", "2008-08-01", "2008-09-01", "2008-10-01", "2008-11-01", "2008-12-01", "2009-01-01", "2009-02-01", "2009-03-01", "2009-04-01", "2009-05-01", "2009-06-01", "2009-07-01", "2009-08-01", "2009-09-01", "2009-10-01", "2009-11-01", "2009-12-01", "2010-01-01", "2010-02-01", "2010-03-01", "2010-04-01", "2010-05-01", "2010-06-01", "2010-07-01", "2010-08-01", "2010-09-01", "2010-10-01", "2010-11-01", "2010-12-01", "2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01", "2011-05-01", "2011-06-01", "2011-07-01", "2011-08-01", "2011-09-01", "2011-10-01", "2011-11-01", "2011-12-01", "2012-01-01", "2012-02-01", "2012-03-01", "2012-04-01", "2012-05-01", "2012-06-01", "2012-07-01", "2012-08-01", "2012-09-01", "2012-10-01", "2012-11-01", "2012-12-01", "2013-01-01", "2013-02-01", "2013-03-01", "2013-04-01", "2013-05-01", "2013-06-01", "2013-07-01", "2013-08-01", "2013-09-01", "2013-10-01", "2013-11-01", "2013-12-01", "2014-01-01", "2014-02-01", "2014-03-01", "2014-04-01", "2014-05-01", "2014-06-01", "2014-07-01", "2014-08-01", "2014-09-01", "2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", "2015-02-01", "2015-03-01", "2015-04-01", "2015-05-01", "2015-06-01", "2015-07-01", "2015-08-01", "2015-09-01", "2015-10-01", "2015-11-01", "2015-12-01", "2016-01-01", "2016-02-01", "2016-03-01", "2016-04-01", "2016-05-01", "2016-06-01", "2016-07-01", "2016-08-01", "2016-09-01", "2016-10-01", "2016-11-01", "2016-12-01", "2017-01-01", "2017-02-01", "2017-03-01", "2017-04-01", "2017-05-01", "2017-06-01", "2017-07-01"]}, "credits": {"enabled": false}, "exporting": {"chartOptions": {"subtitle": null}, "sourceHeight": 900, "sourceWidth": 1600}, "legend": true}
然而,Highcharts将其呈现为:
为什么它会显示每个日期,而不是仅显示this example中的某些日期?
我尝试将返回日期的格式更改为Javascript的原生Date.UTC使用的时间戳,但这只会让它看起来更糟: