0

我正在绘制 Unix 时间戳与权重,因此我的 x 轴范围例如是:1380330622 到 1382696991

Y轴是:83到86左右...

有40个条目。

我的绘图范围基本上设置为每个的最小值<->最大值,并且图形数据显示得很好......但我根本无法让我的 Axes 出现......

最初,高 x 轴数导致分配大量主要刻度,这已解决,但没有轴:

在此处输入图像描述

    -(void)configureAxis{


    graph.plotAreaFrame.axisSet.borderLineStyle = [CPTLineStyle lineStyle];

    // Line styles
    CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
    axisLineStyle.lineWidth = 3.0;
    axisLineStyle.lineCap   = kCGLineCapRound;

    CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
    majorGridLineStyle.lineWidth = 0.75;
    majorGridLineStyle.lineColor = [CPTColor redColor];

    CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
    minorGridLineStyle.lineWidth = 0.25;
    minorGridLineStyle.lineColor = [CPTColor blueColor];

    // Text styles
    CPTMutableTextStyle *axisTitleTextStyle = [CPTMutableTextStyle textStyle];
    axisTitleTextStyle.fontName = @"Helvetica Bold";
    axisTitleTextStyle.fontSize = 14.0;

    // Axes
    // Label x axis with a fixed interval policy
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
    CPTXYAxis *x          = axisSet.xAxis;
    x.separateLayers              = NO;
    x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(82.0f);
    x.majorIntervalLength         = CPTDecimalFromString(@"86400");
    x.minorTicksPerInterval       = 4;
    x.tickDirection               = CPTSignNone;
    x.axisLineStyle               = axisLineStyle;
    x.majorTickLength             = 12.0;
    x.majorTickLineStyle          = axisLineStyle;
    x.majorGridLineStyle          = majorGridLineStyle;
    x.minorTickLength             = 8.0;
    x.minorGridLineStyle          = minorGridLineStyle;
    x.title                       = @"Date";
    x.titleTextStyle              = axisTitleTextStyle;
    x.titleOffset                 = 25.0;
    x.labelingPolicy              = CPTAxisLabelingPolicyAutomatic;


    // Label y axis with a fixed interval policy
    CPTXYAxis *y          = axisSet.yAxis;
    y.separateLayers              = NO;
    y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(1380340622.0f);
    y.majorIntervalLength         = CPTDecimalFromString(@"10");
    y.minorTicksPerInterval       = 4;
    y.tickDirection               = CPTSignNone;
    y.axisLineStyle               = axisLineStyle;
    y.majorTickLength             = 12.0;
    y.majorTickLineStyle          = axisLineStyle;
    y.majorGridLineStyle          = majorGridLineStyle;
    y.minorTickLength             = 8.0;
    y.minorGridLineStyle          = minorGridLineStyle;
    y.title                       = @"Weight in kg";
    y.titleTextStyle              = axisTitleTextStyle;
    y.titleOffset                 = 25.0;
    y.labelingPolicy              = CPTAxisLabelingPolicyAutomatic;





}

这是 numberforplot 的当前输出:

    2013-10-26 11:13:04.509 app[2174:303] The size of the arays for x and y are: 41;41
2013-10-26 11:13:04.509 app[2174:303] XMIN: 111667.172778  XMAX: 112324.4975
2013-10-26 11:13:04.509 app[2174:303] YMIN: 83.225  YMAX: 85.701
2013-10-26 11:13:04.509 app[2174:303] Data dictionary: {
    identifier = WEIGHT;
    "max_x" = "112324.4975";
    "max_y" = "85.701";
    "min_x" = "111667.172778";
    "min_y" = "83.225";
    "x_values" =     (
        "111667.172778",
        "111732.579167",
        "111732.931944",
        "111733.087222",
        "111748.680278",
        "111757.177778",
        "111760.608056",
        "111763.109444",
        "111763.497222",
        "111763.529167",
        "111763.678056",
        "111764.11",
        "111772.890556",
        "111773.146389",
        "111779.491389",
        "111785.4075",
        "111796.832778",
        "111821.3",
        "111846.429722",
        "111869.016389",
        "111892.786389",
        "111916.811111",
        "111941.981944",
        "111942.026389",
        "111965.135833",
        "111989.396667",
        "112012.848611",
        "112038.682778",
        "112061.785",
        "112085.694444",
        "112109.053056",
        "112131.653889",
        "112157.381111",
        "112181.126944",
        "112205.423056",
        "112205.711111",
        "112229.128056",
        "112252.898611",
        "112276.948889",
        "112300.449167",
        "112324.4975"
    );
    "y_values" =     (
        "83.823",
        "84.286",
        "83.807",
        "84.387",
        "83.256",
        "84.799",
        "85.005",
        "85.399",
        "85.414",
        "85.595",
        "85.701",
        "85.493",
        "84.427",
        "83.989",
        "84.462",
        "85.134",
        "83.797",
        "83.454",
        "83.87",
        "83.526",
        "83.512",
        "83.969",
        "84.02",
        "84.009",
        "85.13",
        "84.662",
        "83.869",
        "84.5",
        "83.94",
        "83.225",
        "84.352",
        "84.332",
        "83.617",
        "83.776",
        "84.582",
        "83.869",
        "83.712",
        "84.144",
        "84.048",
        "84.035",
        "84.06"
    );
}
2013-10-26 11:13:04.511 app[2174:303] Adding plot to graph system
2013-10-26 11:13:04.511 app[2174:303] Added... 1
2013-10-26 11:13:04.512 app[2174:303] Number of entries... 41
2013-10-26 11:13:04.512 app[2174:303] Number of entries... 41
2013-10-26 11:13:04.512 app[2174:303] 0,111667.172778
2013-10-26 11:13:04.513 app[2174:303] 1,111732.579167
2013-10-26 11:13:04.513 app[2174:303] 2,111732.931944
2013-10-26 11:13:04.513 app[2174:303] 3,111733.087222
2013-10-26 11:13:04.513 app[2174:303] 4,111748.680278
2013-10-26 11:13:04.513 app[2174:303] 5,111757.177778
2013-10-26 11:13:04.514 app[2174:303] 6,111760.608056
2013-10-26 11:13:04.514 app[2174:303] 7,111763.109444
2013-10-26 11:13:04.514 app[2174:303] 8,111763.497222
2013-10-26 11:13:04.514 app[2174:303] 9,111763.529167
2013-10-26 11:13:04.515 app[2174:303] 10,111763.678056
2013-10-26 11:13:04.515 app[2174:303] 11,111764.11
2013-10-26 11:13:04.515 app[2174:303] 12,111772.890556
2013-10-26 11:13:04.515 app[2174:303] 13,111773.146389
2013-10-26 11:13:04.515 app[2174:303] 14,111779.491389
2013-10-26 11:13:04.516 app[2174:303] 15,111785.4075
2013-10-26 11:13:04.516 app[2174:303] 16,111796.832778
2013-10-26 11:13:04.516 app[2174:303] 17,111821.3
2013-10-26 11:13:04.516 app[2174:303] 18,111846.429722
2013-10-26 11:13:04.516 app[2174:303] 19,111869.016389
2013-10-26 11:13:04.517 app[2174:303] 20,111892.786389
2013-10-26 11:13:04.517 app[2174:303] 21,111916.811111
2013-10-26 11:13:04.517 app[2174:303] 22,111941.981944
2013-10-26 11:13:04.517 app[2174:303] 23,111942.026389
2013-10-26 11:13:04.517 app[2174:303] 24,111965.135833
2013-10-26 11:13:04.518 app[2174:303] 25,111989.396667
2013-10-26 11:13:04.518 app[2174:303] 26,112012.848611
2013-10-26 11:13:04.518 app[2174:303] 27,112038.682778
2013-10-26 11:13:04.518 app[2174:303] 28,112061.785
2013-10-26 11:13:04.518 app[2174:303] 29,112085.694444
2013-10-26 11:13:04.518 app[2174:303] 30,112109.053056
2013-10-26 11:13:04.519 app[2174:303] 31,112131.653889
2013-10-26 11:13:04.519 app[2174:303] 32,112157.381111
2013-10-26 11:13:04.519 app[2174:303] 33,112181.126944
2013-10-26 11:13:04.519 app[2174:303] 34,112205.423056
2013-10-26 11:13:04.519 app[2174:303] 35,112205.711111
2013-10-26 11:13:04.520 app[2174:303] 36,112229.128056
2013-10-26 11:13:04.520 app[2174:303] 37,112252.898611
2013-10-26 11:13:04.520 app[2174:303] 38,112276.948889
2013-10-26 11:13:04.520 app[2174:303] 39,112300.449167
2013-10-26 11:13:04.520 app[2174:303] 40,112324.4975
2013-10-26 11:13:04.521 app[2174:303] Number of entries... 41
2013-10-26 11:13:04.521 app[2174:303] 0,83.823
2013-10-26 11:13:04.521 app[2174:303] 1,84.286
2013-10-26 11:13:04.522 app[2174:303] 2,83.807
2013-10-26 11:13:04.522 app[2174:303] 3,84.387
2013-10-26 11:13:04.522 app[2174:303] 4,83.256
2013-10-26 11:13:04.522 app[2174:303] 5,84.799
2013-10-26 11:13:04.522 app[2174:303] 6,85.005
2013-10-26 11:13:04.523 app[2174:303] 7,85.399
2013-10-26 11:13:04.523 app[2174:303] 8,85.414
2013-10-26 11:13:04.523 app[2174:303] 9,85.595
2013-10-26 11:13:04.523 app[2174:303] 10,85.701
2013-10-26 11:13:04.523 app[2174:303] 11,85.493
2013-10-26 11:13:04.524 app[2174:303] 12,84.427
2013-10-26 11:13:04.524 app[2174:303] 13,83.989
2013-10-26 11:13:04.524 app[2174:303] 14,84.462
2013-10-26 11:13:04.524 app[2174:303] 15,85.134
2013-10-26 11:13:04.524 app[2174:303] 16,83.797
2013-10-26 11:13:04.525 app[2174:303] 17,83.454
2013-10-26 11:13:04.525 app[2174:303] 18,83.87
2013-10-26 11:13:04.525 app[2174:303] 19,83.526
2013-10-26 11:13:04.525 app[2174:303] 20,83.512
2013-10-26 11:13:04.526 app[2174:303] 21,83.969
2013-10-26 11:13:04.526 app[2174:303] 22,84.02
2013-10-26 11:13:04.526 app[2174:303] 23,84.009
2013-10-26 11:13:04.526 app[2174:303] 24,85.13
2013-10-26 11:13:04.526 app[2174:303] 25,84.662
2013-10-26 11:13:04.526 app[2174:303] 26,83.869
2013-10-26 11:13:04.527 app[2174:303] 27,84.5
2013-10-26 11:13:04.527 app[2174:303] 28,83.94
2013-10-26 11:13:04.527 app[2174:303] 29,83.225
2013-10-26 11:13:04.527 app[2174:303] 30,84.352
2013-10-26 11:13:04.528 app[2174:303] 31,84.332
2013-10-26 11:13:04.528 app[2174:303] 32,83.617
2013-10-26 11:13:04.528 app[2174:303] 33,83.776
2013-10-26 11:13:04.528 app[2174:303] 34,84.582
2013-10-26 11:13:04.528 app[2174:303] 35,83.869
2013-10-26 11:13:04.529 app[2174:303] 36,83.712
2013-10-26 11:13:04.529 app[2174:303] 37,84.144
2013-10-26 11:13:04.529 app[2174:303] 38,84.048
2013-10-26 11:13:04.529 app[2174:303] 39,84.035
2013-10-26 11:13:04.529 app[2174:303] 40,84.06
2013-10-26 11:13:04.530 app[2174:303] Number of entries... 41
4

1 回答 1

0

这至少是问题的一部分:CPTDecimalFromDouble(1380340622.0f);

该数字太大而无法用浮点值精确表示(由“f”后缀强制)。Unix 时间是一个整数,所以试试这样的:

y.orthogonalCoordinateDecimal = CPTDecimalFromLong(1380330622);

根据问题中的新信息进行编辑:

您的轴位置超出数据范围。例如,x 轴在 y=82.0 处与 y 轴相交,但绘图范围从 83.225 开始。

x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(y_min);
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(x_min);

如果您总是想将轴固定到绘图区域中的某个点(例如,边缘之一或中间),无论可见数据的范围如何,您都可以使用轴约束而不是正交坐标。

x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
于 2013-10-26T01:31:27.457 回答