Forum


Replies: 6   Views: 153
How to set up line chart without curve when created from a template

Posted by dawenloni  · 27-09-2019 - 22:50

I need to create line chart with straight lines (no curve nor smooth lines), and the chart border with no round borders. When create a doc file from scratch,  using " $docx = new CreateDocx(); ", it is the way like that.

However, when create a doc from a template, such as

$docx = new CreateDocxFromTemplate('files/Template_PT_Resource_Allocation_Form_Grants_2019-09-23.docx');

with the same codes to generate a line chart, things changed. all lines are smoothly curved, and the chart borders have round corners, that are NOT what we want.

 

Any suggetion so we would archive the line charts with straight lines (No curved smoothling lines), and chart borders are not round corners?

Posted by admin  · 28-09-2019 - 09:07

Edited by admin · 28-09-2019 - 09:28

Hello,

You can use any DOCX template to generate the documents, so we recommend you to use your own templates, the templates included in the examples folder were created for the specific samples not for general use so extra styles could be applied.

The addChart method includes options to customize the chart, for example smooth. On https://www.phpdocx.com/api-documentation/word-content/add-chart-Word-document-with-PHP you can read the supported options.

The trial package doesn't include support but if after purchasing a license you have any question or doubt do not hesitate to contact us and we'll generate a custom sample to illustrate how to generate that chart in a template. You could also send the DOCX you need to generate.

We have done some tests using DOCX created from scratch and templates and the output is the same in both cases, how are you adding the chart into the template?

Regards.

Posted by vrietz  · 20-11-2019 - 10:46

Hello,
I have the exact same problem.

When I create a doc file from scratch, my graph looks alright. But when I create a doc from a template, my graph looks different (it has curves, the colors are different, the axis too) . See the code below:

//...
$paramsChart = array(
                    'data' => $data,
                    'type' => 'lineChart',
                    'color' => '2',
                    'chartAlign' => 'center',
                    'showTable' => 1,
                    'sizeX' => '15',
                    'sizeY' => '10',
                    'legendPos' => 'b',
                    'legendOverlay' => '0',
                    'haxLabel' => 'Time',
                    'vaxLabel' => 'Number',
                    'haxLabelDisplay' => 'horizontal',
                    'vaxLabelDisplay' => 'vertical',
                    'hgrid' => '1',
                    'vgrid' => '0',
                    'symbol' => 'circle',
                    'smooth' => false,
                );
// first document
$docx1 = new CreateDocx();
$docx1->addChart($paramsChart);
// second document
$docx2 = new CreateDocxFromTemplate('path_to_file.docx');
$docx2->addChart($paramsChart);

I don't know what I'm doing wrong, please help.

I use PHPdocX 7.5

Posted by admin  · 20-11-2019 - 11:01

Hello,

We have run the following script with phpdocx 9, phpdocx 8 and phpdocx 7.5:

$docx1 = new CreateDocx();

$data = array(
    'legend' => array('Series 1', 'Series 2', 'Series 3'),
    'data' => array(
        array(
            'name' => 'data 1',
            'values' => array(10, 7, 5),
        ),
        array(
            'name' => 'data 2',
            'values' => array(20, 60, 3),
        ),
        array(
            'name' => 'data 3',
            'values' => array(50, 33, 7),
        ),
        array(
            'name' => 'data 4',
            'values' => array(25, 0, 14),
        ),
    ),
);

$paramsChart = array(
    'data' => $data,
    'type' => 'lineChart',
    'color' => '2',
    'chartAlign' => 'center',
    'showTable' => 1,
    'sizeX' => '15',
    'sizeY' => '10',
    'legendPos' => 'b',
    'legendOverlay' => '0',
    'haxLabel' => 'Time',
    'vaxLabel' => 'Number',
    'haxLabelDisplay' => 'horizontal',
    'vaxLabelDisplay' => 'vertical',
    'hgrid' => '1',
    'vgrid' => '0',
    'symbol' => 'circle',
    'smooth' => false,
);

$docx1->addChart($paramsChart);
$docx1->createDocx('output_1.docx');

$docx2 = new CreateDocxFromTemplate('../../files/TemplateSimpleText.docx');

$paramsChart = array(
    'data' => $data,
    'type' => 'lineChart',
    'color' => '2',
    'chartAlign' => 'center',
    'showTable' => 1,
    'sizeX' => '15',
    'sizeY' => '10',
    'legendPos' => 'b',
    'legendOverlay' => '0',
    'haxLabel' => 'Time',
    'vaxLabel' => 'Number',
    'haxLabelDisplay' => 'horizontal',
    'vaxLabelDisplay' => 'vertical',
    'hgrid' => '1',
    'vgrid' => '0',
    'symbol' => 'circle',
    'smooth' => false,
);

$docx2->addChart($paramsChart);
$docx2->createDocx('output_2.docx');

And the chart output is the same in all cases. You can find the template (TemplateSimpleText.docx) in the package.

If you send to contact[at]phpdocx.com the DOCX you are using as template we'll check it; maybe some style is overwriting the styles added.

Regards.

Posted by vrietz  · 20-11-2019 - 13:52

Thank you for answering.

When I use 'TemplateSimpleText.docx', it works as you said.

But if I open it in Word (I use Word 2013) and then save it, the chart output ends up different. Can some versions of Word disrupt the template?

Posted by admin  · 20-11-2019 - 16:01

Hello,

We have opened both DOCX using MS Word 2010, MS Word 2013 and MS Word 2016 and resaved them and in all cases, the chart is the same.

Some versions of MS Word may do minor adjustments when saving (such as margins or colors), but they shouldn't change the document drastically.

If you send to contact[at]phpdocx.com the DOCX before and after being saved using your version MS Word we'll check them to find what changes have been applied.

Regards.

Posted by vrietz  · 20-11-2019 - 16:41

Thanks. I've sent the documents.