xref: /AOO41X/main/chart2/source/tools/StatisticsHelper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir #include "StatisticsHelper.hxx"
31*cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
32*cdf0e10cSrcweir #include "ErrorBar.hxx"
33*cdf0e10cSrcweir #include "macros.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <rtl/math.hxx>
36*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
37*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSink.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/chart/ErrorBarStyle.hpp>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
46*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
47*cdf0e10cSrcweir using ::rtl::OUString;
48*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
49*cdf0e10cSrcweir using namespace ::com::sun::star;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir namespace
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir double lcl_getVariance( const Sequence< double > & rData, sal_Int32 & rOutValidCount,
55*cdf0e10cSrcweir         bool bUnbiasedEstimator )
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     const sal_Int32 nCount = rData.getLength();
58*cdf0e10cSrcweir     rOutValidCount = nCount;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     double fSum = 0.0;
61*cdf0e10cSrcweir     double fQuadSum = 0.0;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < nCount; ++i )
64*cdf0e10cSrcweir     {
65*cdf0e10cSrcweir         const double fData = rData[i];
66*cdf0e10cSrcweir         if( ::rtl::math::isNan( fData ))
67*cdf0e10cSrcweir             --rOutValidCount;
68*cdf0e10cSrcweir         else
69*cdf0e10cSrcweir         {
70*cdf0e10cSrcweir             fSum     += fData;
71*cdf0e10cSrcweir             fQuadSum += fData * fData;
72*cdf0e10cSrcweir         }
73*cdf0e10cSrcweir     }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     double fResult;
76*cdf0e10cSrcweir     if( rOutValidCount == 0 )
77*cdf0e10cSrcweir         ::rtl::math::setNan( & fResult );
78*cdf0e10cSrcweir     else
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         const double fN = static_cast< double >( rOutValidCount );
81*cdf0e10cSrcweir         if( bUnbiasedEstimator )
82*cdf0e10cSrcweir             fResult = (fQuadSum - fSum*fSum/fN) / (fN - 1);
83*cdf0e10cSrcweir         else
84*cdf0e10cSrcweir             fResult = (fQuadSum - fSum*fSum/fN) / fN;
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     return fResult;
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence(
91*cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
92*cdf0e10cSrcweir     bool bPositiveValue, bool bYError,
93*cdf0e10cSrcweir     OUString & rOutRoleNameUsed )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     OUStringBuffer aRole( C2U("error-bars-"));
96*cdf0e10cSrcweir     if( bYError )
97*cdf0e10cSrcweir         aRole.append( sal_Unicode( 'y' ));
98*cdf0e10cSrcweir     else
99*cdf0e10cSrcweir         aRole.append( sal_Unicode( 'x' ));
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     OUString aPlainRole = aRole.makeStringAndClear();
102*cdf0e10cSrcweir     aRole.append( aPlainRole );
103*cdf0e10cSrcweir     aRole.append( sal_Unicode( '-' ));
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     if( bPositiveValue )
106*cdf0e10cSrcweir         aRole = aRole.appendAscii( "positive" );
107*cdf0e10cSrcweir     else
108*cdf0e10cSrcweir         aRole = aRole.appendAscii( "negative" );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     OUString aLongRole = aRole.makeStringAndClear();
111*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
112*cdf0e10cSrcweir         ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aLongRole ));
113*cdf0e10cSrcweir     // try role without "-negative" or "-positive" postfix
114*cdf0e10cSrcweir     if( xLSeq.is())
115*cdf0e10cSrcweir         rOutRoleNameUsed = aLongRole;
116*cdf0e10cSrcweir     else
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir         xLSeq.set( ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aPlainRole ));
119*cdf0e10cSrcweir         if( xLSeq.is())
120*cdf0e10cSrcweir             rOutRoleNameUsed = aPlainRole;
121*cdf0e10cSrcweir         else
122*cdf0e10cSrcweir             rOutRoleNameUsed = aLongRole;
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     return xLSeq;
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir void lcl_setRole(
129*cdf0e10cSrcweir     const Reference< chart2::data::XDataSequence > & xNewSequence,
130*cdf0e10cSrcweir     const OUString & rRole )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     Reference< beans::XPropertySet > xSeqProp( xNewSequence, uno::UNO_QUERY );
133*cdf0e10cSrcweir     if( xSeqProp.is())
134*cdf0e10cSrcweir         xSeqProp->setPropertyValue( C2U("Role"), uno::makeAny( rRole ));
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir void lcl_addSequenceToDataSource(
138*cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
139*cdf0e10cSrcweir     const Reference< chart2::data::XDataSequence > & xNewSequence,
140*cdf0e10cSrcweir     const OUString & rRole )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     Reference< chart2::data::XDataSink > xSink( xDataSource, uno::UNO_QUERY );
143*cdf0e10cSrcweir     Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
144*cdf0e10cSrcweir     if( ! ( xFact.is() && xSink.is() ))
145*cdf0e10cSrcweir         return;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
148*cdf0e10cSrcweir         xFact->createInstance( C2U("com.sun.star.chart2.data.LabeledDataSequence")), uno::UNO_QUERY );
149*cdf0e10cSrcweir     if( xLSeq.is())
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         lcl_setRole( xNewSequence, rRole );
152*cdf0e10cSrcweir         xLSeq->setValues( xNewSequence );
153*cdf0e10cSrcweir         Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences(
154*cdf0e10cSrcweir             xDataSource->getDataSequences());
155*cdf0e10cSrcweir         aSequences.realloc( aSequences.getLength() + 1 );
156*cdf0e10cSrcweir         aSequences[ aSequences.getLength() - 1 ] = xLSeq;
157*cdf0e10cSrcweir         xSink->setData( aSequences );
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir void lcl_setXMLRangePropertyAtDataSequence(
162*cdf0e10cSrcweir     const Reference< chart2::data::XDataSequence > & xDataSequence,
163*cdf0e10cSrcweir     const OUString & rXMLRange )
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     try
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         const OUString aXMLRangePropName( C2U( "CachedXMLRange" ));
168*cdf0e10cSrcweir         Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW );
169*cdf0e10cSrcweir         Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo());
170*cdf0e10cSrcweir         if( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName ))
171*cdf0e10cSrcweir             xProp->setPropertyValue( aXMLRangePropName, uno::makeAny( rXMLRange ));
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir     catch( const uno::Exception & ex )
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir } // anonymous namespace
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir namespace chart
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir double StatisticsHelper::getVariance(
185*cdf0e10cSrcweir     const Sequence< double > & rData,
186*cdf0e10cSrcweir     bool bUnbiasedEstimator /* = false */ )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     sal_Int32 nValCount;
189*cdf0e10cSrcweir     return lcl_getVariance( rData, nValCount, bUnbiasedEstimator );
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir double StatisticsHelper::getStandardDeviation( const Sequence< double > & rData )
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     double fResult = getVariance( rData );
195*cdf0e10cSrcweir     if( ! ::rtl::math::isNan( fResult ))
196*cdf0e10cSrcweir         fResult = sqrt( fResult );
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     return fResult;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir double StatisticsHelper::getStandardError( const Sequence< double > & rData )
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     sal_Int32 nValCount;
204*cdf0e10cSrcweir     double fVar = lcl_getVariance( rData, nValCount, false );
205*cdf0e10cSrcweir     double fResult;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     if( nValCount == 0 ||
208*cdf0e10cSrcweir         ::rtl::math::isNan( fVar ))
209*cdf0e10cSrcweir     {
210*cdf0e10cSrcweir         ::rtl::math::setNan( & fResult );
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir     else
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         // standard-deviation / sqrt(n)
215*cdf0e10cSrcweir         fResult = sqrt( fVar ) / sqrt( double(nValCount) );
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     return fResult;
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
222*cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
223*cdf0e10cSrcweir     bool bPositiveValue,
224*cdf0e10cSrcweir     bool bYError /* = true */ )
225*cdf0e10cSrcweir {
226*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xResult;
227*cdf0e10cSrcweir     if( !xDataSource.is())
228*cdf0e10cSrcweir         return xResult;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     OUString aRole;
231*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
232*cdf0e10cSrcweir         lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, aRole ));
233*cdf0e10cSrcweir     if( xLSeq.is())
234*cdf0e10cSrcweir         xResult.set( xLSeq );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     return xResult;
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > StatisticsHelper::getErrorDataSequenceFromDataSource(
240*cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
241*cdf0e10cSrcweir     bool bPositiveValue,
242*cdf0e10cSrcweir     bool bYError /* = true */ )
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
245*cdf0e10cSrcweir         StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
246*cdf0e10cSrcweir             xDataSource, bPositiveValue,
247*cdf0e10cSrcweir             bYError ));
248*cdf0e10cSrcweir     if( !xLSeq.is())
249*cdf0e10cSrcweir         return Reference< chart2::data::XDataSequence >();
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     return xLSeq->getValues();
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir double StatisticsHelper::getErrorFromDataSource(
255*cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
256*cdf0e10cSrcweir     sal_Int32 nIndex,
257*cdf0e10cSrcweir     bool bPositiveValue,
258*cdf0e10cSrcweir     bool bYError /* = true */ )
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     double fResult = 0.0;
261*cdf0e10cSrcweir     ::rtl::math::setNan( & fResult );
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     Reference< chart2::data::XDataSequence > xValues(
264*cdf0e10cSrcweir         StatisticsHelper::getErrorDataSequenceFromDataSource( xDataSource, bPositiveValue, bYError ));
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir     Reference< chart2::data::XNumericalDataSequence > xNumValues( xValues, uno::UNO_QUERY );
267*cdf0e10cSrcweir     if( xNumValues.is())
268*cdf0e10cSrcweir     {
269*cdf0e10cSrcweir         Sequence< double > aData( xNumValues->getNumericalData());
270*cdf0e10cSrcweir         if( nIndex < aData.getLength())
271*cdf0e10cSrcweir             fResult = aData[nIndex];
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir     else if( xValues.is())
274*cdf0e10cSrcweir     {
275*cdf0e10cSrcweir         Sequence< uno::Any > aData( xValues->getData());
276*cdf0e10cSrcweir         if( nIndex < aData.getLength())
277*cdf0e10cSrcweir             aData[nIndex] >>= fResult;
278*cdf0e10cSrcweir     }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     return fResult;
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir void StatisticsHelper::setErrorDataSequence(
284*cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
285*cdf0e10cSrcweir     const Reference< chart2::data::XDataProvider > & xDataProvider,
286*cdf0e10cSrcweir     const OUString & rNewRange,
287*cdf0e10cSrcweir     bool bPositiveValue,
288*cdf0e10cSrcweir     bool bYError /* = true */,
289*cdf0e10cSrcweir     OUString * pXMLRange /* = 0 */ )
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     Reference< chart2::data::XDataSink > xDataSink( xDataSource, uno::UNO_QUERY );
292*cdf0e10cSrcweir     if( ! ( xDataSink.is() && xDataProvider.is()))
293*cdf0e10cSrcweir         return;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     OUString aRole;
296*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
297*cdf0e10cSrcweir         lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, aRole ));
298*cdf0e10cSrcweir     Reference< chart2::data::XDataSequence > xNewSequence(
299*cdf0e10cSrcweir         xDataProvider->createDataSequenceByRangeRepresentation( rNewRange ));
300*cdf0e10cSrcweir     if( xNewSequence.is())
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         if( pXMLRange )
303*cdf0e10cSrcweir             lcl_setXMLRangePropertyAtDataSequence( xNewSequence, *pXMLRange );
304*cdf0e10cSrcweir         if( xLSeq.is())
305*cdf0e10cSrcweir         {
306*cdf0e10cSrcweir             lcl_setRole( xNewSequence, aRole );
307*cdf0e10cSrcweir             xLSeq->setValues( xNewSequence );
308*cdf0e10cSrcweir         }
309*cdf0e10cSrcweir         else
310*cdf0e10cSrcweir             lcl_addSequenceToDataSource( xDataSource, xNewSequence, aRole );
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir Reference< beans::XPropertySet > StatisticsHelper::addErrorBars(
315*cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
316*cdf0e10cSrcweir     const Reference< uno::XComponentContext > & xContext,
317*cdf0e10cSrcweir     sal_Int32 nStyle,
318*cdf0e10cSrcweir     bool bYError /* = true */ )
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar;
321*cdf0e10cSrcweir     Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
322*cdf0e10cSrcweir     if( !xSeriesProp.is())
323*cdf0e10cSrcweir         return xErrorBar;
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     const OUString aPropName( bYError ? C2U("ErrorBarY") : C2U("ErrorBarX"));
326*cdf0e10cSrcweir     if( !( xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBar ) ||
327*cdf0e10cSrcweir         !xErrorBar.is())
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir         xErrorBar.set( createErrorBar( xContext ));
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir     OSL_ASSERT( xErrorBar.is());
333*cdf0e10cSrcweir     if( xErrorBar.is())
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         xErrorBar->setPropertyValue( C2U("ErrorBarStyle"), uno::makeAny( nStyle ));
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir     xSeriesProp->setPropertyValue( aPropName, uno::makeAny( xErrorBar ));
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     return xErrorBar;
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir Reference< beans::XPropertySet > StatisticsHelper::getErrorBars(
344*cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
345*cdf0e10cSrcweir     bool bYError /* = true */ )
346*cdf0e10cSrcweir {
347*cdf0e10cSrcweir     Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
348*cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar;
349*cdf0e10cSrcweir     const OUString aPropName( bYError ? C2U("ErrorBarY") : C2U("ErrorBarX"));
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     if ( xSeriesProp.is())
352*cdf0e10cSrcweir         xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBar;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     return xErrorBar;
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir bool StatisticsHelper::hasErrorBars(
358*cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
359*cdf0e10cSrcweir     bool bYError /* = true */ )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError ));
362*cdf0e10cSrcweir     sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     return ( xErrorBar.is() &&
365*cdf0e10cSrcweir              ( xErrorBar->getPropertyValue( C2U("ErrorBarStyle")) >>= nStyle ) &&
366*cdf0e10cSrcweir              nStyle != ::com::sun::star::chart::ErrorBarStyle::NONE );
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir void StatisticsHelper::removeErrorBars(
370*cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
371*cdf0e10cSrcweir     bool bYError /* = true  */ )
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError ));
374*cdf0e10cSrcweir     if ( xErrorBar.is())
375*cdf0e10cSrcweir         xErrorBar->setPropertyValue( C2U("ErrorBarStyle"), uno::makeAny(
376*cdf0e10cSrcweir                                          ::com::sun::star::chart::ErrorBarStyle::NONE ));
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir bool StatisticsHelper::usesErrorBarRanges(
380*cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
381*cdf0e10cSrcweir     bool bYError /* = true */ )
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError ));
384*cdf0e10cSrcweir     sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     return ( xErrorBar.is() &&
387*cdf0e10cSrcweir              ( xErrorBar->getPropertyValue( C2U("ErrorBarStyle")) >>= nStyle ) &&
388*cdf0e10cSrcweir              nStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA );
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir } //  namespace chart
392