2014-07-10 2 views
0

웹 서비스에서 JSON 데이터를 사용하여 막대 그래프를 생성하려고합니다. 기본적으로 "JSON"데이터를 사용하여 "막대 그래프"를 표시해야합니다.Blackberry 10을 사용하여 막대 그래프를 생성하는 방법 네이티브 메소드

기본적으로 나는 Android 개발자이며 Blackberry 10 Native에 익숙하지 않으므로 Blackberry에 대해 많이 알지 못합니다. 따라서 Blackberry-10에서 그래프를 생성하는 것에 대해 도움이 될만한 사람이 있으면 알려주세요.

나는 구글과 내가 어디에서 할 수 있는지를 많이 조사했지만 어떤 결론도 내리지 못했다. 아직도 나는 그것에 대한 해결책을 찾고있다. 그래서 기본적으로 나의 "JSON"데이터는 다음 형식으로되어있다.

{"Ax":"3:41","Ay":"04:41","Bx":"10:47 ","By":"12:47","Cx":"18:30","Cy":"19:30","Az":3,"Bz":2,"Cz":1,"condition":2} 

여기 "Ax":"3:41","Ay":"04:41"이 파라미터는 시작 작업의 종료 시간이며, 마침내는 그 그래프에 기초 "Az":3,"Bz":2,"Cz":1 같은 시간의 총 수를 계산하여 생성된다. 그래서 유사하게 내 그래프는이

http://postimg.org/image/nb6dnpwax/

처럼 보일 것이다 내가이 기반으로 그래프를 생성 할 수있는 방법을 제발 도와주세요, 내가 그래프를 생성하는 데 대해 참조 한 링크의 일부는

http://elycharts.com/examples
http://g.raphaeljs.com/입니다
How to make charts/graphs (such as line graphs, bar graphs, circle graphs), etc. in C++, Qt, QML, Blackberry 10 Cascades Beta 3 SDK?
http://devblog.blackberry.com/2014/01/conference-app-secrets-part-3-json-vs-xml/

한 가지 내가 분명히 mentio입니다 ning은 Blackberry-10과 qml 및 C++ 방식을 사용하는 솔루션을 원하므로 Java 및 기타 모든 다른 방법을 제안하지 마십시오.

나를 도와 주셔서 미리 감사드립니다.

+0

:

APP_NAME = BarGraph CONFIG += qt warn_on cascades10 LIBS += -lbb include(config.pri) 

다음은 결과입니다. 가장 쉬운 방법은 컨테이너를 사용하여 자신 만의 그래프를 만드는 것입니다. 내 머리 꼭대기에서 주 컨테이너를 절대 레이아웃으로 설정 한 다음 각 바에 컨테이너를 배치하는 것이 좋습니다. – hyarion

+0

집에 돌아와 내 코드 기반에 액세스 할 때 게시 할 해결책이 있습니다. 이 응용 프로그램의 스크린 샷을보십시오 : http://appworld.blackberry.com/webstore/content/128442/?lang=en&countrycode=CA 세번째는 막대 그래프를 보여줍니다. 이 기법은 기본적으로 상당히 좋은 드로잉 패키지를 가지고있는 QImage를 드로잉 한 다음 Cascades ImageView를 전송합니다. – Richard

+0

@Hyarion, 귀하의 제안에 감사드립니다, 나는 또한 귀하의 솔루션을 시도하고 내 작업을 마칠 때 당신에게 돌아갈 것입니다. – user3660803

답변

3

따라서이 문서는 BlackBerry Support Forums에 있습니다. 모든 기본 사항이 있지만 런타임에 생성 된 이미지로 많은 작업을 수행하여 캡슐화 할 클래스를 작성하기로 결정했습니다. 여기에 요청 된대로 Cascades 템플릿 중 하나를 기반으로하는 간단한 샘플이 있습니다. 당신은 또한에 문서에 익숙해 져야합니다 :

그리고 BlackBerry GIT Hub에서 샘플 파일을.

QML 파일 :

/* 
* DrawableImage.hpp 
* 
* Created on: Jul 11, 2014 
*  Author: richard 
*/ 

#ifndef DRAWABLEIMAGE_HPP_ 
#define DRAWABLEIMAGE_HPP_ 

#include <bb/ImageData> 
#include <QtGui/QImage> 
#include <bb/cascades/ImageView> 

namespace net 
{ 
    namespace test 
    { 

     class DrawableImage : public QImage 
     { 
     public: 
      DrawableImage(); 
      DrawableImage(QSize imageSize, QImage::Format format); 
      virtual ~DrawableImage(); 

      void emitRenderingBegin(); 
      void emitRenderingFinished(); 

      DrawableImage& operator = (const QImage &image) { QImage::operator =(image); return *this; } 

      QPainter  &painter(); 

     public: 
      void updateToView(bb::cascades::ImageView *imageView); 

     private: 
       void deleteBuffer(); 

       QPainter  m_painter; 
       QSize   m_sizeInPixels; 
       unsigned char* m_buffer; // pixel data in PixelBufferData format 
     }; 

    } /* namespace test */ 
} /* namespace net */ 

#endif /* DRAWABLEIMAGE_HPP_ */ 

그리고 CPP 파일 : 여기

/* 
* Copyright (c) 2011-2014 BlackBerry Limited. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

import bb.cascades 1.2 

Page { 
    Container { 
     layout: DockLayout { 

     } 
     Label { 
      // Localized text with the dynamic translation and locale updates support 
      text: qsTr("Bar Graph") + Retranslate.onLocaleOrLanguageChanged 
      textStyle.base: SystemDefaults.TextStyles.BigText 
      horizontalAlignment: HorizontalAlignment.Center 
     } 
     ImageView { 
      objectName: "barGraph" 
      verticalAlignment: VerticalAlignment.Center 
      horizontalAlignment: HorizontalAlignment.Center 
     } 
    } 
} 

헤더 파일입니다

/* 
* DrawableImage.cpp 
* 
* Created on: Jul 11, 2014 
*  Author: richard 
*/ 

#include <src/DrawableImage.hpp> 

namespace net 
{ 
    namespace test 
    { 

     DrawableImage::DrawableImage() 
      : m_painter(), m_sizeInPixels(0,0), m_buffer(NULL) 
     { 
      // TODO Auto-generated constructor stub 

     } 

     DrawableImage::DrawableImage(QSize imageSize, QImage::Format format) 
      : QImage(imageSize, format), m_painter(), m_sizeInPixels(0,0), m_buffer(NULL) 
     { 

     } 


     DrawableImage::~DrawableImage() { 
      // TODO Auto-generated destructor stub 
     } 

     /* 
     void DrawableImage::emitRenderingBegin() { 
      emit renderingBegin(); 
     } 

     void DrawableImage::emitRenderingFinished() { 
      emit renderingFinished(); 
     } 
     */ 

     QPainter& DrawableImage::painter() { 
      if (!m_painter.isActive()) { 
       m_painter.begin(this); 
      } 

      return m_painter; 
     } 

     void DrawableImage::deleteBuffer() 
     { 
      if (m_buffer != 0) 
      { 
       delete [] m_buffer; 
       m_buffer = 0; 
      } 
     } 

     void DrawableImage::updateToView(bb::cascades::ImageView *imageView) { 
      if (m_painter.isActive()) { 
       m_painter.end(); 
      } 

      Q_ASSERT(imageView != NULL); 

      QImage swapped  = rgbSwapped(); 
      QSize swappedSize = swapped.size(); 

      int w = swappedSize.width(); 
      int h = swappedSize.height(); 

      int numBytes = w * h * 4; 
      if (swappedSize != m_sizeInPixels) 
      { 
       deleteBuffer(); 
       m_sizeInPixels = QSize(w, h); 
       m_buffer = new uchar[numBytes]; 
      } 

      // Copy the memory over. 
      // We'll add defensive code in case rgbSwapped has a different size 
      const uchar* from = swapped.constBits(); 
      int numFromBytes = swapped.numBytes(); 
      int numToCopy = std::min(numFromBytes, numBytes); 

      memcpy(m_buffer, from, numToCopy); 
      if (numToCopy < numBytes) 
      { 
       memset(m_buffer + numToCopy, 0x00, numBytes - numToCopy); 
      } 

      bb::ImageData imageData = bb::ImageData::fromPixels(m_buffer, bb::PixelFormat::RGBA_Premultiplied, 
            m_sizeInPixels.width(), 
            m_sizeInPixels.height(), 
            m_sizeInPixels.width() * 4); 

      imageView->setImage(imageData); 
     } 


    } /* namespace test */ 
} /* namespace net */ 

그리고 여기 applicationui.cpp (applicationui.hpp입니다 수정되지 않음) :

/* 
* Copyright (c) 2011-2014 BlackBerry Limited. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

#include "applicationui.hpp" 

#include <bb/cascades/Application> 
#include <bb/cascades/QmlDocument> 
#include <bb/cascades/AbstractPane> 
#include <bb/cascades/LocaleHandler> 

#include <src/DrawableImage.hpp> 

using namespace bb::cascades; 
using namespace net::test; 

ApplicationUI::ApplicationUI() : 
     QObject() 
{ 
    // prepare the localization 
    m_pTranslator = new QTranslator(this); 
    m_pLocaleHandler = new LocaleHandler(this); 

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); 
    // This is only available in Debug builds 
    Q_ASSERT(res); 
    // Since the variable is not used in the app, this is added to avoid a 
    // compiler warning 
    Q_UNUSED(res); 

    // initial load 
    onSystemLanguageChanged(); 

    // Create scene document from main.qml asset, the parent is set 
    // to ensure the document gets destroyed properly at shut down. 
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); 

    // Create root object for the UI 
    AbstractPane *root = qml->createRootObject<AbstractPane>(); 

    /* 
    * This code exercises the DrawableImage 
    */ 
    QSize graphImageSize(700, 700); 
    DrawableImage graph; 
    ImageView* graphImageView = root->findChild<ImageView*>("barGraph"); 

    // Initialise graph and fill with transparent black. 
     graph = QImage(graphImageSize, QImage::Format_ARGB32_Premultiplied); 
     graph.fill(Qt::black); 

     // Set the background mode 
     graph.painter().setBackgroundMode(Qt::TransparentMode); 

     // Set rendering hints 
     graph.painter().setRenderHint(QPainter::Antialiasing, true); 

     for (int i = 0; i < 10; i++) { 

      int x = i * (graphImageSize.width()/10); 
      int h = i * (graphImageSize.height()/10) + graphImageSize.height()/20; 
      int w = graphImageSize.width()/10 - 20; 

      graph.painter().fillRect(x + 10, graphImageSize.height()-h, w, h, Qt::darkGreen); 
     } 

    // Once the image is drawn transfer it to the Cascades ImageView 
    graph.updateToView(graphImageView); 

    // Set created root object as the application scene 
    Application::instance()->setScene(root); 
} 

void ApplicationUI::onSystemLanguageChanged() 
{ 
    QCoreApplication::instance()->removeTranslator(m_pTranslator); 
    // Initiate, load and install the application translation files. 
    QString locale_string = QLocale().name(); 
    QString file_name = QString("BarGraph_%1").arg(locale_string); 
    if (m_pTranslator->load(file_name, "app/native/qm")) { 
     QCoreApplication::instance()->installTranslator(m_pTranslator); 
    } 
} 

또한에 LIBS 행을 추가해야합니다.프로 파일 : BB10에 대한 그래프 라이브러리는 아직까지 내가 알고 있어요로서이 없습니다

enter image description here

+0

안녕하세요, 리차드, 답변 해 주셔서 감사합니다. 코드에이를 구현해 드리겠습니다. 답장을 보내 드리지만 빠른 답변을드립니다. 고마워요. – user3660803

+0

안녕하세요. 리차드,이 완벽한 예제를 어떻게 구현할 수 있습니까? 그렇지 않으면 "qml"과 "C++"에 대한 완전한 예제를 제공 할 수 있습니까?이 예제를 어떻게 구현할 수 있을지 모르겠습니다. 협조 해 주셔서 감사합니다. – user3660803

+0

유스 케이스를 어떻게 알지 못하는지 구체적으로 알 수는 없지만 이것이 도움이 될 것입니다. – Richard

관련 문제