有间隙的 pChart 时间线 [英] pChart timeline with gaps

查看:46
本文介绍了有间隙的 pChart 时间线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 pChart 来呈现样本值与日期的简单折线图.我有基本的工作,但我如何处理日期的差距?样本已经按季度平均,但不是每个季度都有样本.有时会跳过一两个季度.

I want to use pChart to render a simple line graph of a sample value vs. the date. I have the basics working, but how do I handle gaps in the date? The samples are already averaged by the quarter year, but not every quarter has a sample. Sometimes it skips a quarter or two.

目前,这些间隙在 X 轴上一个接一个地压缩,而不是在数轴上按自然顺序隔开.

Currently, these gaps are compressed on the X axis one after another, instead of being spaced out in their natural order in a number line.

数据来自 MySQL 数据库.我可能错过了一些简单的东西.有人可以帮忙吗?

The data is coming from a MySQL database. I'm probably missing something simple. Can anyone help?

#Array variables.
$date       = "";
$value      = "";

#Fetch the database rows, and sort them into arrays.
while ($row = mysql_fetch_array($result))
{
    $date[] = $row["date"];
    $value[]    = $row["value"];
}

#Create a chart data object.
$MyData = new pData();

#Pass the data to the chart.
$MyData->addPoints($date, "Date");
$MyData->addPoints($value, "Value");

#Configure labels.
$MyData->setAxisName(0,"Value");

#Set the date as the X axis.
$MyData->setAbscissa("Date");
$MyData->setAbscissaName("Date");

推荐答案

这是试图使用 drawLineChart() 函数,而它应该使用 drawScatterLineChart() 函数> 功能.这些差异没有得到很好的解释,但至关重要.

This is trying to use the drawLineChart() function, when it should be using the drawScatterLineChart() function. The differences aren't very well explained, but are crucial.

折线图"不使用数轴作为其独立轴.它用于具有非数字轴的图表,例如一年中的几个月.该轴不像自然数轴那样记录间隙,因为文本不一定具有可以以逻辑方式排序的值.

A "Line Chart" doesn't use a number line for its independent axis. It's used for charts with a non-numerical axis, like months of the year. This axis doesn't register gaps like a natural number line would, because text doesn't necessarily have values which can be ordered in a logical way.

散点图"是一个普通的 XY 图表,其轴上有适当的数字线.它像人们期望的那样对价值观的差距做出反应.这应该是文档中的默认示例.

The "Scatter Line Chart" is a normal XY chart with proper number lines on its axes. It responds to gaps in values like one would expect. This should really be the default example in the documentation.

这篇关于有间隙的 pChart 时间线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆