You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Roman Kashitsyn <ro...@gmail.com> on 2011/05/14 09:14:58 UTC

XSSF Chart model

Hello. In my current project I have to create xlsx charts programmaticaly.
As I can see, at the moment POI has not enought capabilities for that. So I
want to collaborate with POI developers to teach POI to work with charts. I
have proposed code to allow user create new charts (
http://apache-poi.1045710.n5.nabble.com/DO-NOT-REPLY-Bug-51196-New-PATCH-Patch-to-simplify-XSSFChart-creation-tp4392907p4392907.html
patch 51196 ), but they still have to fill chart content by themselves.


The next step is to allow users to create different charts without direct
xmlbeans library usage. ECMA-376 describes 16 chart types. So we need to
organize classes in some rational model. I thought a lot about it and here
is my proposal: lets add to XSSFChart factory method, say,
plot(XSSFChartData), to plot a specific data on a chart. XSSFChartData will
be an interface (or an abstract class) that incapsulates specific plot logic
(i.e. working with CTPlotArea).

The implementation could be something like that:


/* XSSFChartData.java */
public interface XSSFChartData() {
    void fillChart(CTPlotArea ctArea);
}

/* XSSFChart.java */
public void plot(XSSFChartData data) {
    data.fillChart(getCTChart().getPlotArea());
}

/* XSSFScetterChartData.java */
public class XSSFScetterChartData implements XSSFChartData {
    public void fillChart(CTPlotArea area) {
        CTScetterChart scetterChart = area.addNewScetterChart();
        /* .... */
    }
}


Here is a code snippet illustrating the idea:

XSSFChart chart = drawing.createChart(anchor);
XSSFScetterChartData chartData = new XSSFScetterChartData();
XSSFScetterChartData.Serie serie = chartData.addSerie();
serie.setXValues(range);
serie.setYValues(anotherRange);
chart.plot(chartData);



I think proposed class names not the best ones, if you know better ones -
welcome.



Here are the benefits of such approach:

no any if\switches: polymorphism rules;
the same data can be plotted in multiple charts - orthogonality is always a
plus;

I think a new package should be introduced to contain chart data classes
(suppose, org.apache.poi.xssf.usermodel.charts).


What do you think about all this?

Thank you in advance

Roman Kashitsyn



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XSSF-Chart-model-tp4395176p4395176.html
Sent from the POI - Dev mailing list archive at Nabble.com.

Re: XSSF Chart model

Posted by Roman Kashitsyn <ro...@gmail.com>.
Hi,

I have applied your comments and made the chart drawing api more uniform. I
have also added new test cases, so build of poi-ooxml-schemas now performs
right. Please find details in the latest attachment of
https://issues.apache.org/bugzilla/show_bug.cgi?id=51196

Best regards,
Roman

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Re-XSSF-Chart-model-tp4398326p4409599.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: XSSF Chart model

Posted by Roman Kashitsyn <ro...@gmail.com>.
Hi,

I have done with my first part of chart drawing api draft. Please see most
resent attachment
(https://issues.apache.org/bugzilla/attachment.cgi?id=27021&action=diff) of
bug 51196 (https://issues.apache.org/bugzilla/show_bug.cgi?id=51196) and its
comments for details.

It is big enough (more than 1000 loc). Not all chart drawing functionality
declared in org.apache.poi.ss.usermodel.charts package, so it is not
possible to work with charts in uniform manner yet, but now it is not very
hard to implement. There is a lot of work and this is just the first brick
in the wall.

Best regards,
Roman

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Re-XSSF-Chart-model-tp4398326p4406081.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: XSSF Chart model

Posted by Roman Kashitsyn <ro...@gmail.com>.
Hi Yegor,

Thank you very much for your response.

At the moment I don't have sample implementation, but I am going to start
development today so a  will be ready soon (I will provide patch as soon as
possible).

As for common interfaces, I will try to redesign solution to achieve uniform
approach to charts. I think, this will require some factory methods to hide
real implementation... Any way, we will discuss it when there will be a
working solution.

Best regards,
Roman Kashitsyn

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Re-XSSF-Chart-model-tp4398326p4399435.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: XSSF Chart model

Posted by Yegor Kozlov <ye...@dinom.ru>.
Roman,

You are very much welcome to contribute. Support for Excel charts is a
commonly asked question on the mailing lists and it would be a really
valuable contribution.

I think it would be good to design the chart API in terms of common ss
interfaces, so that in future we will have both XSSF and HSSF
implementations.  XSSFChartData would become ChartData in
org.apache.poi.ss.usermodel.charts, etc.

The proposed architecture of classes looks good. Do you already have a
sample implementation or you just planning it? In any case, don't
hesitate to attach it to Bugzilla (Bug 51196 or a new one).
Hoping to see it in the upcoming release of POI 3.8!

Regards,
Yegor

On Sat, May 14, 2011 at 11:14 AM, Roman Kashitsyn
<ro...@gmail.com> wrote:
>
> Hello. In my current project I have to create xlsx charts programmaticaly.
> As I can see, at the moment POI has not enought capabilities for that. So I
> want to collaborate with POI developers to teach POI to work with charts. I
> have proposed code to allow user create new charts (
> http://apache-poi.1045710.n5.nabble.com/DO-NOT-REPLY-Bug-51196-New-PATCH-Patch-to-simplify-XSSFChart-creation-tp4392907p4392907.html
> patch 51196 ), but they still have to fill chart content by themselves.
>
>
> The next step is to allow users to create different charts without direct
> xmlbeans library usage. ECMA-376 describes 16 chart types. So we need to
> organize classes in some rational model. I thought a lot about it and here
> is my proposal: lets add to XSSFChart factory method, say,
> plot(XSSFChartData), to plot a specific data on a chart. XSSFChartData will
> be an interface (or an abstract class) that incapsulates specific plot logic
> (i.e. working with CTPlotArea).
>
> The implementation could be something like that:
>
>
> /* XSSFChartData.java */
> public interface XSSFChartData() {
>    void fillChart(CTPlotArea ctArea);
> }
>
> /* XSSFChart.java */
> public void plot(XSSFChartData data) {
>    data.fillChart(getCTChart().getPlotArea());
> }
>
> /* XSSFScetterChartData.java */
> public class XSSFScetterChartData implements XSSFChartData {
>    public void fillChart(CTPlotArea area) {
>        CTScetterChart scetterChart = area.addNewScetterChart();
>        /* .... */
>    }
> }
>
>
> Here is a code snippet illustrating the idea:
>
> XSSFChart chart = drawing.createChart(anchor);
> XSSFScetterChartData chartData = new XSSFScetterChartData();
> XSSFScetterChartData.Serie serie = chartData.addSerie();
> serie.setXValues(range);
> serie.setYValues(anotherRange);
> chart.plot(chartData);
>
>
>
> I think proposed class names not the best ones, if you know better ones -
> welcome.
>
>
>
> Here are the benefits of such approach:
>
> no any if\switches: polymorphism rules;
> the same data can be plotted in multiple charts - orthogonality is always a
> plus;
>
> I think a new package should be introduced to contain chart data classes
> (suppose, org.apache.poi.xssf.usermodel.charts).
>
>
> What do you think about all this?
>
> Thank you in advance
>
> Roman Kashitsyn
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/XSSF-Chart-model-tp4395176p4395176.html
> Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org