Hi,
othman wrote:
Hi,
I figured out the error i was making :
i had to replace service name "com.sun.star.chart2.LabeledDataSequence" with
"com.sun.star.chart2.data.LabeledDataSequence"
Now i can get some interesting results: i got the stock chart drawn; however
it seems that the x-axis values are not set properly (see screen shot) and
also it seems that OO keep the line chart drawn on canvas and superimpose
the candlestick chart over it (see attached image)
my questions:
1) how can i remove the default line chart and instruct OO not to draw it.
Remove it from the chart type container.
2) why the x-axis values are not set correctly ? x-axis values are for dates
.
Only the scatter chart does support x-values. The x axis for candle
stick charts is a category axes which displays just strings.
3) is the method createLabeledSequence() correctly creating the sequences ?
especially for "values-x" ?
With chart2 API the categories have to be attached to the according x
axis. When you create the chart using the standard API set parameter
'bRowHeaders' to true in the method addNewByName().
http://api.openoffice.org/docs/common/ref/com/sun/star/table/XTableCharts.html
You then can manipulate the created chart afterwards with the chart2 API.
Ingrid
here is my code :
----------------------------------------------------------------------
XEmbeddedObjectSupplier xEmbeddedObjSupplier = (XEmbeddedObjectSupplier)
UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, xtablechart);
XInterface xInterface =
xEmbeddedObjSupplier.getEmbeddedObject();
com.sun.star.chart2.XChartDocument oChart =
(com.sun.star.chart2.XChartDocument) UnoRuntime.queryInterface(
com.sun.star.chart2.XChartDocument.class, xInterface);
/* let the Calc document create a data provider, set it at the
chart*/
com.sun.star.chart2.data.XDataProvider oDataProv =
oChart.getDataProvider();
com.sun.star.chart2.XDiagram oDiagram=oChart.getFirstDiagram();
//insert a coordinate system into the diagram
com.sun.star.chart2.XCoordinateSystemContainer oCoordSysCnt=
(com.sun.star.chart2.XCoordinateSystemContainer)UnoRuntime.queryInterface(com.sun.star.chart2.XCoordinateSystemContainer.class,
oDiagram);
com.sun.star.chart2.XCoordinateSystem[] oCoordSys=
oCoordSysCnt.getCoordinateSystems();
// Query the coordinate system for interface
com::sun::star::chart2::XChartTypeContainer
com.sun.star.chart2.XChartTypeContainer oChartTypeCnt=
(com.sun.star.chart2.XChartTypeContainer)UnoRuntime.queryInterface(com.sun.star.chart2.XChartTypeContainer.class,
oCoordSys[0]);
// get the servie manager from the office
xMCF = xContext.getServiceManager();
Object object = xMCF.createInstanceWithContext(
"com.sun.star.chart2.CandleStickChartType", xContext);
com.sun.star.chart2.XChartType
stockChartType=(com.sun.star.chart2.XChartType) UnoRuntime.queryInterface(
com.sun.star.chart2.XChartType.class, object);
//add candlestick chart type
oChartTypeCnt.addChartType(stockChartType);
com.sun.star.chart2.XDataSeriesContainer dataSeriesCnt=
(com.sun.star.chart2.XDataSeriesContainer)UnoRuntime.queryInterface(com.sun.star.chart2.XDataSeriesContainer.class,
stockChartType);
object = xMCF.createInstanceWithContext(
"com.sun.star.chart2.DataSeries", xContext);
com.sun.star.chart2.XDataSeries
oSeries=(com.sun.star.chart2.XDataSeries) UnoRuntime.queryInterface(
com.sun.star.chart2.XDataSeries.class, object);
// System.out.println(dataSeriesCnt);
dataSeriesCnt.addDataSeries(oSeries);
com.sun.star.chart2.data.XDataSink
dataSink=(com.sun.star.chart2.data.XDataSink) UnoRuntime.queryInterface(
com.sun.star.chart2.data.XDataSink.class, oSeries);
// data sequences
com.sun.star.chart2.data.XLabeledDataSequence dLabeledSequence =
createLabeledSequence(xContext, oDataProv, "A", "values-x");
com.sun.star.chart2.data.XLabeledDataSequence oLabeledSequence =
createLabeledSequence(xContext, oDataProv, "B", "values-first");
com.sun.star.chart2.data.XLabeledDataSequence hLabeledSequence =
createLabeledSequence(xContext, oDataProv, "C", "values-max");
com.sun.star.chart2.data.XLabeledDataSequence lLabeledSequence =
createLabeledSequence(xContext, oDataProv, "D", "values-min");
com.sun.star.chart2.data.XLabeledDataSequence cLabeledSequence =
createLabeledSequence(xContext, oDataProv, "E", "values-last");
com.sun.star.chart2.data.XLabeledDataSequence[]
aLabeledSequence={dLabeledSequence,oLabeledSequence,hLabeledSequence,lLabeledSequence,cLabeledSequence};
dataSink.setData(aLabeledSequence);
private static com.sun.star.chart2.data.XLabeledDataSequence
createLabeledSequence(XComponentContext xContext,
com.sun.star.chart2.data.XDataProvider oDataProv,String column,String
role_values) throws Exception {
com.sun.star.chart2.data.XDataSequence oSequence =
oDataProv.createDataSequenceByRangeRepresentation("$audusd_xls.$"+column+"$1:$"+column+"$1740"
);
XPropertySet cProp = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, oSequence );
XMultiComponentFactory xMCF = xContext.getServiceManager();
cProp.setPropertyValue("Role", role_values);
Object object = xMCF.createInstanceWithContext(
"com.sun.star.chart2.data.LabeledDataSequence", xContext);
com.sun.star.chart2.data.XLabeledDataSequence
oLabeledSequence=(com.sun.star.chart2.data.XLabeledDataSequence)
UnoRuntime.queryInterface(
com.sun.star.chart2.data.XLabeledDataSequence.class, object);
oLabeledSequence.setValues(oSequence);
return oLabeledSequence;
}
------------------------------------------------------------------------
http://www.nabble.com/file/p19124025/chart.jpg chart.jpg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]