开发者

Can not see year on graph's x axis that plot by flot

Thanks for those who looked at this post and i would like to post some update with my findings: This is my javascript to plot a graph on a page by using flot,

        var dataSet1 = [[1249102800000, 34.50553], [1249189200000, 27.014463], [1249275600000, 26.7805], [1249362000000, 33.08871], [1249448400000, 51.987762], [1249534800000, 56.868233]];
        var dataSet2 = [[1249102800000, 3.405], [1249189200000, 2.701], [1249275600000, 2.678], [1249362000000, 3.308], [1249448400000, 5.187], [1249534800000, 5.668]];

        function doPlot(position) {
            $.plot($("#placeholder"),
                [{ data: dataSet1, label: "Data Set 1" },
                    { data: dataSet2, label: "Data Set 2", yaxis: 2}],
            {
                series: {
                    lines: { show: true },
                    points: { show: true }
                },
                grid: {
                    hoverable: true,
                    clickable: true
                },
                xaxes: [{ mode: 'time',
                    t开发者_如何学JAVAimeFormat: "%d-%m-%y",
                    minTickSize: [1, 'day']
                }],
                yaxes: [{ min: 0 },
                    {
                        alignTicksWithAxis: position == "right" ? 1 : null,
                        position: position
                    }],
                legend: { position: 'sw' }
            });

now i am able to get the day and month on the x axis of the graph, but still not years, looks like the timeFormat: "%d-%m-%y" does not have any impacts. Again anyone has any thoughts??


a bit disappointed that no one in here gives me a hint, but of course i fully understand since no one knows everything.

Finally i fixed it by my own effect, and i would like to share my finding in here and hopefully can benefit other folks, here you go:

I need to write a function to format the date, and this is the function

function dateFormatter(v) {
            return (new Date(v).toLocaleDateString());
        }

this is the x axis that calls that function:

xaxes: [{ mode: 'time',
                    tickFormatter: dateFormatter,
                    minTickSize: [1, 'day']
                }],

it does achieve what i needed though it is not perfect since the date is like this: Sunday, 2 August 2009, but what i want actually is Aug 2 2009, nevertheless, thsi one: Sunday, 2 August 2009, serves the purpose too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜