1

我正在尝试访问

<chart:guide>

来自屏幕控制器的 value 属性,但我找不到任何获取器来访问它。xml 块是这样的:

<chart:valueAxes>
 <chart:axis position="LEFT"
  stackType="REGULAR"
  title="Graph Title">
  <chart:guides>
   <chart:guide
    value="0"
    inside="true"
    lineAlpha="1"
   />
  </chart:guides>
 </chart:axis>
</chart:valueAxes>

我需要在运行时设置指南的值。有什么建议吗?

4

1 回答 1

1

Let's say we have the following SerialChart:

<chart:serialChart id="serialChart"
                   caption="Serial chart"
                   height="100%"
                   width="100%"
                   categoryField="x">
    <chart:graphs>
        <chart:graph valueField="y"/>
    </chart:graphs>
    <chart:valueAxes>
        <chart:axis position="LEFT">
            <chart:guides>
                <chart:guide value="12"
                             inside="true"
                             lineAlpha="1"/>
            </chart:guides>
        </chart:axis>
    </chart:valueAxes>
    <chart:data>
        <chart:item>
            <chart:property name="x" value="10"/>
            <chart:property name="y" value="12"/>
        </chart:item>
        <chart:item>
            <chart:property name="x" value="11"/>
            <chart:property name="y" value="2"/>
        </chart:item>
        <chart:item>
            <chart:property name="x" value="12"/>
            <chart:property name="y" value="120"/>
        </chart:item>
        <chart:item>
            <chart:property name="x" value="13"/>
            <chart:property name="y" value="16"/>
        </chart:item>
    </chart:data>
</chart:serialChart>

You can simply get ValueAxis and then get Guide object by index or iterate collection and find by id (optional attribute of Guide):

@Inject
private SerialChart serialChart;

ValueAxis valueAxis = serialChart.getValueAxes().get(0);
Guide guide = valueAxis.getGuides().get(0);
guide.setValue(15);

serialChart.repaint();

Note, if we want to change already displayed chart configuration then we have to call repaint() method.

If you use CUBA 6.4 or older, you have to obtain Configuration object first using getConfiguration() method and cast it to appropriate chart type as shown here: https://doc.cuba-platform.com/charts-6.4/cdp_screen_controller.html

于 2017-05-09T16:35:55.647 回答