JQPlot堆叠条形每个堆叠标签计数而不是累积(增量)计数

时间:2022-05-10 05:45:32

I want to display label text in stead of segment total for each label.

我想显示标签文本而不是每个标签的分段总数。

Like, 2, 7, 14 should be in stacked bar with 2, 7, 14 and then 23 is total. But currently in exmaple it is showing segment total - first bar is empty and then 2, 2+7=9, and total = 23 (9+14).

比如,2,7,14应该是堆叠的条形,有2个,7个,14个,然后是23个。但目前在exmaple中它显示了段总数 - 第一个栏为空,然后是2,2 + 7 = 9,总计= 23(9 + 14)。

JQ Plot shows (stacked bar column graph - 3rd graph): http://www.jqplot.com/tests/bar-charts.php

JQ图显示(堆积条形图 - 第3图):http://www.jqplot.com/tests/bar-charts.php

I want like this url like highchart for label count see example: http://www.highcharts.com/demo/column-stacked

我想像标签计数的高图一样这个网址见示例:http://www.highcharts.com/demo/column-stacked

Please let me know if I can go with solution then it would be great help...

请告诉我,如果我可以使用解决方案那么这将是很好的帮助......

4 个解决方案

#1


6  

I have a solution for it as it seems that independent of the value of the stackedValue parameter the values of the stacked bars are always summed up.

我有一个解决方案,因为它似乎独立于stackedValue参数的值,堆积条的值总是相加。

My solution to this problem involved:

我对这个问题的解决方案包括:

  • adding of one more series which serves as the sum, the values you fill it with are all the same (i.e. 3) as their only role is to position the labels,

    添加一个作为总和的系列,你填充它的值都是相同的(即3),因为它们唯一的作用是定位标签,

  • making the last series (5th) invisible and its shadow nearly transparent,

    使最后一个系列(第5个)看不见,它的阴影几乎透明,

  • and using the labels on each series directly rather than letting the script decide what to put there, otherwise it would obviously sum up the values.

    并直接使用每个系列上的标签,而不是让脚本决定放在那里,否则它显然会总结这些值。

My solution could be found here.

我的解决方案可以在这里找到。


EDIT

I have recently spotted that there already was a solution for this problem available here.

我最近发现这里已经有了解决这个问题的方法。

#2


1  

On the summation issue: You've stumbled across a jqplot bug.

在总结问题上:你偶然发现了一个jqplot错误。

If you'll open jqplot.pointLabels.js, take a look at the code starting around line 172/173:

如果您打开jqplot.pointLabels.js,请查看从第172/173行开始的代码:

var d = this._plotData;

If you'll update it to read

如果你要更新它以阅读

var d = this._plotData; 
if (p.stackSeries) {
    var d = this.data;
}

When you call the chart, use something similar to this in your series options:

当您调用图表时,请在系列选项中使用与此类似的内容:

pointLabels: { show: true, stackedValue: false, stackSeries: true }

You'll be able to use the PointLabels stackedValue attribute to turn off the stacked summing.

您将能够使用PointLabels stackedValue属性来关闭堆叠求和。

The fix for the stackedValue bug is detailed here.

这里详细介绍了stackedValue错误的修复方法。

jmva answered your question regarding label placement.

jmva回答了有关标签放置的问题。

#3


0  

To display the values inside the bar just modify css .jqplot-point-label property on local page, this works in the JQPlot demo page:

要显示栏内的值,只需修改本地页面上的css .jqplot-point-label属性,这在JQPlot演示页面中有效:

.jqplot-point-label {
      font-size:.75em;
      z-index: 2;
      /* Add some margin to get values into the bar */
      margin-top: 24px;
}

You can also try PointLabel properties like ypadding for a more polite approach. For sum features refer to this solved thread.

您还可以尝试像ypadding这样的PointLabel属性,以获得更礼貌的方法。对于总和功能,请参阅此解决的线程。

#4


0  

Boro's solution works for me, however, if you need the legend, you will have one more item in the legend which may not be what you expect. I have used Boro's solution and have the legend independent of the jqplot object.

Boro的解决方案对我有用,但是,如果你需要这个传奇,你将在传奇中再添一个项目,这可能不是你所期望的。我已经使用了Boro的解决方案并且拥有独立于jqplot对象的图例。

#1


6  

I have a solution for it as it seems that independent of the value of the stackedValue parameter the values of the stacked bars are always summed up.

我有一个解决方案,因为它似乎独立于stackedValue参数的值,堆积条的值总是相加。

My solution to this problem involved:

我对这个问题的解决方案包括:

  • adding of one more series which serves as the sum, the values you fill it with are all the same (i.e. 3) as their only role is to position the labels,

    添加一个作为总和的系列,你填充它的值都是相同的(即3),因为它们唯一的作用是定位标签,

  • making the last series (5th) invisible and its shadow nearly transparent,

    使最后一个系列(第5个)看不见,它的阴影几乎透明,

  • and using the labels on each series directly rather than letting the script decide what to put there, otherwise it would obviously sum up the values.

    并直接使用每个系列上的标签,而不是让脚本决定放在那里,否则它显然会总结这些值。

My solution could be found here.

我的解决方案可以在这里找到。


EDIT

I have recently spotted that there already was a solution for this problem available here.

我最近发现这里已经有了解决这个问题的方法。

#2


1  

On the summation issue: You've stumbled across a jqplot bug.

在总结问题上:你偶然发现了一个jqplot错误。

If you'll open jqplot.pointLabels.js, take a look at the code starting around line 172/173:

如果您打开jqplot.pointLabels.js,请查看从第172/173行开始的代码:

var d = this._plotData;

If you'll update it to read

如果你要更新它以阅读

var d = this._plotData; 
if (p.stackSeries) {
    var d = this.data;
}

When you call the chart, use something similar to this in your series options:

当您调用图表时,请在系列选项中使用与此类似的内容:

pointLabels: { show: true, stackedValue: false, stackSeries: true }

You'll be able to use the PointLabels stackedValue attribute to turn off the stacked summing.

您将能够使用PointLabels stackedValue属性来关闭堆叠求和。

The fix for the stackedValue bug is detailed here.

这里详细介绍了stackedValue错误的修复方法。

jmva answered your question regarding label placement.

jmva回答了有关标签放置的问题。

#3


0  

To display the values inside the bar just modify css .jqplot-point-label property on local page, this works in the JQPlot demo page:

要显示栏内的值,只需修改本地页面上的css .jqplot-point-label属性,这在JQPlot演示页面中有效:

.jqplot-point-label {
      font-size:.75em;
      z-index: 2;
      /* Add some margin to get values into the bar */
      margin-top: 24px;
}

You can also try PointLabel properties like ypadding for a more polite approach. For sum features refer to this solved thread.

您还可以尝试像ypadding这样的PointLabel属性,以获得更礼貌的方法。对于总和功能,请参阅此解决的线程。

#4


0  

Boro's solution works for me, however, if you need the legend, you will have one more item in the legend which may not be what you expect. I have used Boro's solution and have the legend independent of the jqplot object.

Boro的解决方案对我有用,但是,如果你需要这个传奇,你将在传奇中再添一个项目,这可能不是你所期望的。我已经使用了Boro的解决方案并且拥有独立于jqplot对象的图例。