简体   繁体   English

系列在HighCharts中不起作用

[英]Series Not Working in HighCharts

So I am creating a highcharts bar chart in a function inside my jQuery script, and it was working fine until I tried to incorporate different colors for each bar of the bar chart. 因此,我在jQuery脚本中的一个函数中创建了一个高图表条形图,并且在我尝试为条形图的每个条形图合并不同的颜色之前,它都工作正常。 My code is basically as follows 我的代码基本上如下

function BarChart(title, gType, list, numbers){
    var data = [];
    var allData = [];
    var series = [];
    var len = numbers.length;
    var colors = ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', '#f15c80', '#e4d354', '#8085e8', '#8d4653', '#91e8e1'];
    for(i=0; i<len; i++){
        data.push({
            y: numbers[i],
            color:colors[i]
        });
        allData.push(data[i]);
    }
    for(i=0; i<len; i++){
        series.push({
            name: list[i],
            data: allData[i]
        });
    }

Then I go on and create the chart and for series, I simply put 然后,我继续创建图表,然后针对系列,我简单地把

series: series

But no bars come up, only the legend, the title, the yAxis title and the xAxis title. 但是没有栏出现,只有图例,标题,yAxis标题和xAxis标题。 If you can help me out that be great, hopefully my question is clear enough! 如果您能帮助我,那就太好了,希望我的问题很清楚! Thanks! 谢谢!

PS 聚苯乙烯

when I just put 当我刚放

series:[{
data: data
}] 

it works, but then all the legend says is Series 1 and I don't want that, I want it to actually show the name of each data with its corresponding color, thanks again! 它可以正常工作,但是所有图例都说是Series 1,我不希望这样,我希望它实际显示每个数据的名称及其相应的颜色,再次感谢!

I solved my own problem, but just for reference to anyone else who runs into this problem, its rater simple. 我解决了自己的问题,但仅供参考,遇到此问题的任何人(其评分者都很简单)。 Write this code, 编写这段代码,

plotOptions:{
series:{
    colorByPoint: true
}}

And highcharts will color each bar/column/line individually. 高图将分别为每个条形图/列/行上色。

For reference here is the highcharts page that showed me this: http://api.highcharts.com/highcharts#plotOptions.bar 作为参考,这里是向我显示以下内容的highcharts页面: http ://api.highcharts.com/highcharts#plotOptions.bar

In case you were still looking into the "Series 1" problem in the legend. 如果您仍在研究图例中的“系列1”问题。 I found an interesting way to have each point be it's own series and still group correctly on the x-axis. 我找到了一种有趣的方式来使每个点成为自己的系列,并且仍然正确地在x轴上分组。 It works by abusing bar stacking: 它通过滥用条码堆叠来工作:

plotOptions: {
  series: {
    stacking: 'normal'
  }
},

and setting an increment x value on each data point: 并在每个数据点上设置增量x值:

data.forEach(function(val, i) {
    seriesData.push({
      name: categories[i],
      color: colors[(i % colors.length)],
      data: [{
        x: i,
        y: val
      }]
    });
  });

Here is a working fiddle built from an example I derived from the highcharts docs: 这是从我从highcharts文档衍生的示例构建的工作提琴:

http://jsfiddle.net/89efeqhs/ http://jsfiddle.net/89efeqhs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM