如何更改highcharts中的粒度?

时间:2016-01-31 17:55:42

标签: highcharts jasper-reports

是否可以更改图形的粒度?我有这样的时间表:

Example

如何更改粒度?该数据不会显示在几天而是几个月。例如:9月,10月,12月等。

代码报告:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-31T20:54:38 -->
<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="Blank_A4_Landscape" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a0a85c1c-ef3e-4a4d-bca5-2569e695b407">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="ireport.jasperserver.report.resource" value="/public/Blank_A4_Landscape_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/public/Blank_A4_Landscape"/>
    <subDataset name="Dataset1" uuid="7d75e5f3-311c-4d74-8f4f-13af8f33cc78">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
        <queryString>
            <![CDATA[SELECT top 100 * FROM Orders --WHERE  "ORDERS"."SHIPPEDDATE"  > NOW() - INTERVAL 30 DAY;]]>
        </queryString>
        <field name="ORDERID" class="java.lang.Integer"/>
        <field name="CUSTOMERID" class="java.lang.String"/>
        <field name="EMPLOYEEID" class="java.lang.Integer"/>
        <field name="ORDERDATE" class="java.sql.Timestamp"/>
        <field name="REQUIREDDATE" class="java.sql.Timestamp"/>
        <field name="SHIPPEDDATE" class="java.sql.Timestamp"/>
        <field name="SHIPVIA" class="java.lang.Integer"/>
        <field name="FREIGHT" class="java.math.BigDecimal"/>
        <field name="SHIPNAME" class="java.lang.String"/>
        <field name="SHIPADDRESS" class="java.lang.String"/>
        <field name="SHIPCITY" class="java.lang.String"/>
        <field name="SHIPREGION" class="java.lang.String"/>
        <field name="SHIPPOSTALCODE" class="java.lang.String"/>
        <field name="SHIPCOUNTRY" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[Select  * From Orders]]>
    </queryString>
    <field name="ORDERID" class="java.lang.Integer"/>
    <field name="CUSTOMERID" class="java.lang.String"/>
    <field name="EMPLOYEEID" class="java.lang.Integer"/>
    <field name="ORDERDATE" class="java.sql.Timestamp"/>
    <field name="REQUIREDDATE" class="java.sql.Timestamp"/>
    <field name="SHIPPEDDATE" class="java.sql.Timestamp"/>
    <field name="SHIPVIA" class="java.lang.Integer"/>
    <field name="FREIGHT" class="java.math.BigDecimal"/>
    <field name="SHIPNAME" class="java.lang.String"/>
    <field name="SHIPADDRESS" class="java.lang.String"/>
    <field name="SHIPCITY" class="java.lang.String"/>
    <field name="SHIPREGION" class="java.lang.String"/>
    <field name="SHIPPOSTALCODE" class="java.lang.String"/>
    <field name="SHIPCOUNTRY" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="533" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="80" width="791" height="295" uuid="d836a1b4-c816-4f45-b0f8-0c3ac80a37a0"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="StackedColumn">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.pie.showInLegend" value="true"/>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="chart.backgroundColor">
                            <hc:propertyExpression><![CDATA[new java.awt.Color(-16777216)]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset>
                            <dataset>
                                <datasetRun subDataset="Dataset1" uuid="a05e665b-8ead-41d2-a6e8-3ebad99d8c4d"/>
                            </dataset>
                        </multiAxisDataset>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{SHIPPEDDATE}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <dataAxis axis="Columns"/>
                        <multiAxisMeasure name="Measure1" class="java.lang.Integer" calculation="DistinctCount">
                            <labelExpression><![CDATA["Total Orders"]]></labelExpression>
                            <valueExpression><![CDATA[$F{ORDERID}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Measure1"/>
                </hc:chart>
            </componentElement>
        </band>
    </title>
</jasperReport>

1 个答案:

答案 0 :(得分:2)

将您的查询更改为月份的groupcount数据

示例(mysql语法)

SELECT DATE_FORMAT(SHIPPEDDATE,'%y %M') as LABEL, COUNT(ORDERID) AS CNT_ORDERID 
FROM Orders 
GROUP BY YEAR(SHIPPEDDATE), MONTH(SHIPPEDDATE)
ORDER BY SHIPPEDDATE

注意:这会更改Dataset1中的字段(仅2,LABELCNT_ORDERID)和bucketExpressionvalueExpression将指向新字段