每行有多个系列的图表 [英] Chart with multiple series on each row

查看:77
本文介绍了每行有多个系列的图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此表格执行 iReport 图表

I'm trying to do an iReport chart with this table

name|totalcalls|handled|abandoned|rejected

customerservice|300|100|100|100

itsupport|500|300|100|100

这个想法是在这种情况下应该有2个图表,通过将图表放入详细信息行可以轻松解决。

The idea is that there should be 2 charts in this case, that was easily solved by putting the chart into the details row.

但我无法弄清楚如何让 iReport 将最后3列(处理,放弃,拒绝)视为不同系列。

But I cannot figure out how to make iReport treat the 3 last columns (handled, abandoned, rejected) as different series.

理想情况下,我想做一个如下所示的叠加条形图:

Ideally I want to do a stacked barchart that looks like this:

customerservice|-100-|-100-|-100-

itsupport|---300---|-100-|100

我不知道如何使这项工作。

I have no clue how to make this work.

推荐答案

为实现这一目标,你可以使用堆积条形图。打开iReport并将图表元素从调色板拖放到报表设计器。在向导中选择 Stacked Bar ,然后单击完成

To achieve this you can use a stacked bar chart. Open iReport and drag and drop the chart element from the palette to the report designer. In the wizard select Stacked Bar, then click Finish.

右键单击图表并选择图表数据> 详细信息

Right click on the chart and select Chart Data > Details:


  • 点击添加,进入系列表达式:已处理,类别表达式: $ F {name} ,值表达式: $ F {处理} ,点击确定

  • 添加,系列表达式:被遗弃,类别表达式: $ F {name} ,值表达式: $ F {abandoned} 确定

  • 添加,系列表达式:已拒绝,类别表达式: $ F {name} ,值表达式: $ F {被拒绝} 确定

  • click Add, enter Series Expression: "Handled", Category Expression: $F{name}, Value Expression: $F{handled}, click Ok
  • Add, Series Expression: "Abandoned", Category Expression: $F{name}, Value Expression: $F{abandoned}, Ok
  • Add, Series Expression: "Rejected", Category Expression: $F{name}, Value Expression: $F{rejected}, Ok

然后点击关闭。现在,在报表设计器中选择图表对象,然后在属性面板中将 Orientation 更改为 horizo​​ntal

Then click Close. Now select the chart object in the report designer and change in the properties panel Orientation to horizontal.

我放将图表放入汇总带中,将两行数据保存在一个图表中。如果需要,您可以为详细信息区域中配置的图表应用相同的设置,以获得类似的输出。

I put the chart into the summary band holding both rows of data in a single chart. You can apply the same settings for the chart being configured in the detail band for a similar output if required.

我还附上了JRXML以供进一步参考:

I also attach the JRXML for further reference:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report7" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="42d0d6ab-85f6-496b-8e61-c3d7588cfd8e">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[select  'customerservice' as name, 300 as totalcalls, 100 as handled, 100 as abandoned, 100 as rejected
union select 'itsupport', 500, 300, 100, 100]]>
    </queryString>
    <field name="name" class="java.lang.String"/>
    <field name="totalcalls" class="java.lang.Long"/>
    <field name="handled" class="java.lang.Long"/>
    <field name="abandoned" class="java.lang.Long"/>
    <field name="rejected" class="java.lang.Long"/>
    <summary>
        <band height="92">
            <stackedBarChart>
                <chart>
                    <reportElement uuid="f0bfeda6-003e-40c0-8d75-0c61bc620978" x="0" y="0" width="555" height="92"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <categoryDataset>
                    <categorySeries>
                        <seriesExpression><![CDATA["Handled"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{name}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{handled}]]></valueExpression>
                    </categorySeries>
                    <categorySeries>
                        <seriesExpression><![CDATA["Abandoned"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{name}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{abandoned}]]></valueExpression>
                    </categorySeries>
                    <categorySeries>
                        <seriesExpression><![CDATA["Rejected"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{name}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{rejected}]]></valueExpression>
                    </categorySeries>
                </categoryDataset>
                <barPlot>
                    <plot orientation="Horizontal"/>
                    <itemLabel/>
                </barPlot>
            </stackedBarChart>
        </band>
    </summary>
</jasperReport>

这篇关于每行有多个系列的图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆