Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Programatically modifying chart Post Reply Post New Topic
Author Message
ryan_the_nerd
Newbie
Newbie


Joined: 26 Nov 2012
Online Status: Offline
Posts: 3
Quote ryan_the_nerd Replybullet Topic: Programatically modifying chart
     Posted: 28 Nov 2012 at 12:37am
I am attempting to programatically modify a chart within a Crystal Report using Java. The java then feeds the report to the viewer. Removing an item works, modifying does not.

Removing an item works, modifying does not.

//Experiment : Can we programatically modify a chart?
            ReportDefController rdc = reportClientDocument.getReportDefController();
            ReportObjectController roc = rdc.getReportObjectController();
            ReportObjects ros = roc.getReportObjectsByKind(ReportObjectKind.chart);

            logger.debug("There are " + ros.size() + " chart items");
            IChartObject ro = null;
            IChartObject ro_original = null;
            ISection iSection = null;
            for (int i = 0; i <ros.size(); i++){
               ro = (IChartObject)ros.get(i);
               ro_original = (IChartObject)ros.get(i);
               String rn = ro.getName();
               ChartStyle cs = (ChartStyle) ro.getChartStyle();
               cs.setEnableDataAxisAutoRange(false);
               cs.setEnableShowLegend(false);
               cs.setEnableDepthEffect(true);
               cs.setIsVertical(true);
               cs.setDataAxisMinValue(-2.0);
               cs.setDataAxisMaxValue(100.0);
               Double minVal = (Double)cs.getDataAxisMinValue();
               Double maxVal = (Double)cs.getDataAxisMaxValue();
               boolean d = cs.getEnableDepthEffect();
               boolean l = cs.getEnableShowLegend();
               boolean a = cs.getEnableDataAxisAutoRange();
               boolean v = cs.getIsVertical();
               ro.setChartStyle(cs);
               int sectionCode = ro.getSectionCode();
               iSection = rdc.getReportDefinition().getDetailArea().getSections().getSection(0);
               try
               {
                    //roc.modify((IChartObject)ros.get(i), ro);
                    rdc.modifyChartObject((IChartObject)ros.get(i), ro);
                    reportClientDocument.refreshReportDocument();
                    reportClientDocument.save();
               } catch (ReportSDKException e){
                    writer.println("Couldn't modify graph");
                    e.printStackTrace();
               }
               logger.debug("Chart named "+rn + " With Min Val " + minVal + " and Max Val " + maxVal +" with depth " + d + " and legend " + l + " autorange " + a + " Vertical " + v);
            }

I've tried the modify method of ReportObjectController and the modifychartobject method of ReportDefController, and have tried refreshReportDocument and save to attempt to get something to update, but nothing's happening. Logger is showing that the values are updating as you'd expect. Any ideas?
IP IP Logged
ryan_the_nerd
Newbie
Newbie


Joined: 26 Nov 2012
Online Status: Offline
Posts: 3
Quote ryan_the_nerd Replybullet Posted: 28 Nov 2012 at 3:15am
For info for others, I solved this by changing ro's declaration to a .clone(false) so that the roc.modify would recognise the original object and the fact that the new object was a separate item.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum