phpspreadsheet - lines without markers in chart
phpspreadsheet - lines without markers in chart
I am using phpspreadsheet to generate line charts. Almost everything is fine, but I don't get how to change plot style.
Here is what I have:
function createChart($sheet, $sheetname, $data) {
$count = $data["custom"]["count"];
$sheet->getColumnDimensionByColumn(1)->setAutoSize(true);
$sheet->setCellValueByColumnAndRow(1, 1, $data["custom"]["type"]);
for($j=0; $j < $count; $j++)
$sheet->setCellValueByColumnAndRow(1, $j + 2, $data["custom"]["dates"][$j]);
for($i=0; $i< count($data["series"]); $i++) {
$sheet->setCellValueByColumnAndRow($i+2, 1, $data["series"][$i]["name"]);
$sheet->getColumnDimensionByColumn($i+2)->setAutoSize(true);
for($j=0; $j < $count; $j++)
{
$value = $data["series"][$i]["data"][$j] ? $data["series"][$i]["data"][$j] : 0;
$sheet->setCellValueByColumnAndRow($i+2, $j + 2, $value);
}
}
$dsl=array();
for($i=0; $i< count($data["series"]); $i++) {
$series = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $sheetname . '!' .
$sheet->getCellByColumnAndRow($i+2, 1)->getCoordinate(), NULL, 1, , NULL, NULL);
array_push($dsl, $series);
}
$xal=array(
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $sheetname . '!'.
$sheet->getCellByColumnAndRow(1, 2)->getCoordinate() . ':' .
$sheet->getCellByColumnAndRow(1, $count + 2)->getCoordinate() , NULL, $count)
);
$dsv = array();
for($i=0; $i< count($data["series"]); $i++) {
$series = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $sheetname . '!'.
$sheet->getCellByColumnAndRow($i+2, 2)->getCoordinate() . ':' .
$sheet->getCellByColumnAndRow($i+2, $count + 2)->getCoordinate() , NULL, $count);
array_push($dsv, $series);
}
$type = "";
switch($data["series"][0]["type"]) {
case CHART_TYPE_BARCHART:
$type = DataSeries::TYPE_BARCHART;
break;
case CHART_TYPE_LINECHART:
$type = DataSeries::TYPE_LINECHART;
break;
default:
$type = DataSeries::TYPE_LINECHART;
}
$ds = new DataSeries(
$type,
DataSeries::GROUPING_STANDARD,
range(0, count($dsv)-1),
$dsl,
$xal,
$dsv,
null,
true,
DataSeries::STYLE_MARKER
);
$pa = new PlotArea(NULL, array($ds));
$legend = new Legend(Legend::POSITION_BOTTOM, NULL, false);
$title = new Title($data["title"]["text"]);
$chart = new Chart(
'chart1',
$title,
$legend,
$pa,
0,
0,
NULL,
NULL
);
$chart->setTopLeftPosition( $sheet->getCellByColumnAndRow(count($data["series"]) + 3, 1)->getCoordinate());
$chart->setBottomRightPosition($sheet->getCellByColumnAndRow(count($data["series"]) + 17, 40)->getCoordinate());
$sheet->addChart($chart);
}
Specifically, I would like to draw lines without markers.
I tried passing all possible values the $plotStyle
parameter of the Dataseries
constructor, but this didn't have any effect.
$plotStyle
Dataseries
I know from the API docs that there is a Properties
class which defines many constants influencing a chart's style, but I don't get how to use it, as it doesn't seem to be referenced by other classes.
Properties
I also know from this question that one can set style properties of the document being created, is this the right way? How to navigate to the chart's properties?
1 Answer
1
I found it myself. All I needed to do was passing the string "none"
to the parameter $marker
of the DataSeriesValues
constructor:
"none"
$marker
DataSeriesValues
DataSeriesValues::__construct(
string $dataType = self::DATASERIES_TYPE_NUMBER,
string $dataSource = null
, null|mixed $formatCode = null,
int $pointCount = 0,
mixed $dataValues = ,
null|mixed $marker = null,
null|string $fillColor = null
)
So the relevant part of my code becomes:
for($i=0; $i< count($data["series"]); $i++) {
$series = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $sheetname . '!'.
$sheet->getCellByColumnAndRow($i+2, 2)->getCoordinate() . ':' .
$sheet->getCellByColumnAndRow($i+2, $count + 2)->getCoordinate() , NULL, $count, , "none");
array_push($dsv, $series);
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment