You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XDDFRadarChartData.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xddf.usermodel.chart;
  16. import java.util.Map;
  17. import org.apache.poi.util.Beta;
  18. import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
  19. import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
  20. import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarChart;
  21. import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarSer;
  22. import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarStyle;
  23. import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
  24. @Beta
  25. public class XDDFRadarChartData extends XDDFChartData {
  26. private CTRadarChart chart;
  27. public XDDFRadarChartData(CTRadarChart chart, Map<Long, XDDFChartAxis> categories,
  28. Map<Long, XDDFValueAxis> values) {
  29. this.chart = chart;
  30. for (CTRadarSer series : chart.getSerList()) {
  31. this.series.add(new Series(series, series.getCat(), series.getVal()));
  32. }
  33. defineAxes(chart.getAxIdArray(), categories, values);
  34. }
  35. @Override
  36. public void setVaryColors(boolean varyColors) {
  37. if (chart.isSetVaryColors()) {
  38. chart.getVaryColors().setVal(varyColors);
  39. } else {
  40. chart.addNewVaryColors().setVal(varyColors);
  41. }
  42. }
  43. public RadarStyle getStyle() {
  44. return RadarStyle.valueOf(chart.getRadarStyle().getVal());
  45. }
  46. public void setStyle(RadarStyle style) {
  47. CTRadarStyle radarStyle = chart.getRadarStyle();
  48. if (radarStyle == null) {
  49. radarStyle = chart.addNewRadarStyle();
  50. }
  51. radarStyle.setVal(style.underlying);
  52. }
  53. @Override
  54. public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
  55. XDDFNumericalDataSource<? extends Number> values) {
  56. final int index = this.series.size();
  57. final CTRadarSer ctSer = this.chart.addNewSer();
  58. ctSer.addNewCat();
  59. ctSer.addNewVal();
  60. ctSer.addNewIdx().setVal(index);
  61. ctSer.addNewOrder().setVal(index);
  62. final Series added = new Series(ctSer, category, values);
  63. this.series.add(added);
  64. return added;
  65. }
  66. public class Series extends XDDFChartData.Series {
  67. private CTRadarSer series;
  68. protected Series(CTRadarSer series, XDDFDataSource<?> category,
  69. XDDFNumericalDataSource<? extends Number> values) {
  70. super(category, values);
  71. this.series = series;
  72. }
  73. protected Series(CTRadarSer series, CTAxDataSource category, CTNumDataSource values) {
  74. super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values));
  75. this.series = series;
  76. }
  77. @Override
  78. protected CTSerTx getSeriesText() {
  79. return series.getTx();
  80. }
  81. @Override
  82. public void setShowLeaderLines(boolean showLeaderLines) {
  83. if (!series.isSetDLbls()) {
  84. series.addNewDLbls();
  85. }
  86. if (series.getDLbls().isSetShowLeaderLines()) {
  87. series.getDLbls().getShowLeaderLines().setVal(showLeaderLines);
  88. } else {
  89. series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines);
  90. }
  91. }
  92. @Override
  93. protected CTAxDataSource getAxDS() {
  94. return series.getCat();
  95. }
  96. @Override
  97. protected CTNumDataSource getNumDS() {
  98. return series.getVal();
  99. }
  100. }
  101. }