I find a way to do it. Just to share with others as POI's API is not clear
yet. Hope it help.

    /*
     * Create a new series in chart
     * And assign a Name to it
     */
    public static void createNewSeriesWithName(HSSFWorkbook wb, HSSFChart
chart,
            String series_title, Name name) throws Exception
    {
        HSSFSeries series = chart.createSeries();
        series.setSeriesTitle(series_title);
        Ptg[] ptg = new Ptg[1];
        ptg[0] = new NameXPtg(0, wb.getNameIndex(name.getNameName()));

series.getDataValues().setReferenceType(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
        series.getDataValues().setFormulaOfLink(ptg);
    }

BTW, this only works if you have at least 1 existing series in the chart.
You can add a dummy series and remove it later.

Cheers,
Le Vinh Dat, Kevin

On Tue, Aug 17, 2010 at 8:41 PM, Le Vinh Dat (Kevin) <[email protected]>wrote:

> Yeap yeap, normally, I did that way. But sometimes, the number of series
> are dynamic, not fixed.
>
>
> Sincerely yours,
> Le Vinh Dat, Kevin
>
> On Tue, Aug 17, 2010 at 8:27 PM, Nick Burch <[email protected]>wrote:
>
>> On Tue, 17 Aug 2010, Le Vinh Dat (Kevin) wrote:
>>
>>> Is it possible to set Series value to Name in HSSFChart?
>>> E.g.:
>>> Series value = 'SampleChart.xls'!NetView_Rx_inf0"
>>>
>>
>> I think the recommended way is to create a template in excel with the
>> chart using the name, then use poi to edit the name once you have populated
>> the data
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>

Reply via email to