Hi,
I'm trying to insert an XYDiagram into a Writer (!) document by code.
But I can't figure out how to get any data into it. All the examples on
the web are always for Calc, never for Writer. The code I have got is below.
Everything works fine until I want to create my sequences.
Reference < XTextContent > insertChart(const Reference < XController >
&xCtrl) {
Reference < XTextCursor > xModelCursor;
Reference < XText > xDocumentText = getDocumentText(xCtrl, xModelCursor);
Reference < XTextContent > xChart = createObject(xCtrl, CLSID_CHART);
// Insert the chart
Reference < XTextRange > xRange(xModelCursor, UNO_QUERY_THROW);
xDocumentText->insertTextContent(xRange, xChart, true);
// Get a factory to create objects for this chart
Reference < XEmbeddedObjectSupplier > xEOS(xChart, UNO_QUERY_THROW);
Reference < com::sun::star::chart::XChartDocument >
cDoc(xEOS->getEmbeddedObject(), UNO_QUERY_THROW);
Reference < XMultiServiceFactory > cDocMSF(cDoc, UNO_QUERY_THROW);
// Make sure that we have a clear interpretation of where data series are
Reference < XPropertySet > cDocProps (cDoc, UNO_QUERY_THROW);
cDocProps->setPropertyValue(OU("DataRowSource"),
makeAny(::com::sun::star::chart::ChartDataRowSource_ROWS));
// Create a new XYDiagram
Reference < ::com::sun::star::chart::XDiagram >
xyDiagram(cDocMSF->createInstance(OU("com.sun.star.chart.XYDiagram")),
UNO_QUERY_THROW);
cDoc->setDiagram(xyDiagram);
// Create two new sequences based on the two first default sequences,
setting the roles correctly for an XYDiagram
Reference < ::com::sun::star::chart2::XChartDocument >
chart(xEOS->getEmbeddedObject(), UNO_QUERY_THROW);
chart->createInternalDataProvider(true);
Reference< XDataProvider > dataProvider = chart->getDataProvider();
Reference< XDataSequence > seqDataX =
dataProvider->createDataSequenceByRangeRepresentation(OU("0"));
Reference < XPropertySet > seqProps (seqDataX, UNO_QUERY_THROW);
seqProps->setPropertyValue(OU("Role"), makeAny(OU("values-x")));
Reference< XDataSequence > seqLabelX =
dataProvider->createDataSequenceByRangeRepresentation(OU("label 0"));
Reference< XDataSequence > seqDataY =
dataProvider->createDataSequenceByRangeRepresentation(OU("1"));
seqProps = Reference< XPropertySet >(seqDataY, UNO_QUERY_THROW);
seqProps->setPropertyValue(OU("Role"), makeAny(OU("values-y")));
Reference< XDataSequence > seqLabelY =
dataProvider->createDataSequenceByRangeRepresentation(OU("label 1"));
// Get write access to the chart series
Reference< ::com::sun::star::chart2::XDiagram > diagram =
chart->getFirstDiagram();
Reference< XCoordinateSystemContainer > xCoordCnt(diagram,
UNO_QUERY_THROW);
Reference< XChartTypeContainer >
xChartTypeCnt(xCoordCnt->getCoordinateSystems()[0], UNO_QUERY_THROW);
Reference< XDataSeriesContainer >
chartType(xChartTypeCnt->getChartTypes()[0], UNO_QUERY_THROW);
===>
===> Here the problems start: This gives an "unsatisified query" error
===>
// Create two sequences
Sequence< Reference< XLabeledDataSequence > > sequences(2);
sequences[0] = Reference <
::com::sun::star::chart2::data::XLabeledDataSequence >
(cDocMSF->createInstance(OU("com.sun.star.chart2.data.LabeledDataSequence")),
UNO_QUERY_THROW);
sequences[1] = Reference <
::com::sun::star::chart2::data::XLabeledDataSequence >
(cDocMSF->createInstance(OU("com.sun.star.chart2.data.LabeledDataSequence")),
UNO_QUERY_THROW);
sequences[0]->setValues(seqDataX);
sequences[0]->setLabel(seqLabelX);
sequences[1]->setValues(seqDataY);
sequences[1]->setLabel(seqLabelY);
Reference< XDataSeries > xDataSeries = ????;
Reference< XDataSink > XYSink(xDataSeries, UNO_QUERY_THROW);
XYSink->setData(sequences);
chartType->addDataSeries(xDataSeries);
return xChart;
} // insertChart()
Context
- How to create an object of type ::com::sun::star::chart2::data::XLabeledDataSequence ? · Jan Rheinländer
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.