検索
ホームページJava&#&チュートリアルデータ視覚化のために Java で座標平面と Y 軸ラベルを回転するにはどうすればよいですか?

How do I rotate the coordinate plane and y-axis labels in Java for data visualization?

Java でのデータとテキストの座標平面の回転

この問題は、データ ポイントのプロットと Y 軸上のラベルの回転における課題を扱います。データプロットの。提供されたコードは、データとラベルをプロットするための基本構造を定義しますが、次の 2 つの問題に遭遇します。

  • 原点と y 軸の方向が原因で、データ ポイントが正しくプロットされません。
  • Y-軸ラベルが画面に表示されません。

問題の解決

これらの問題に対処するには、次の変更に焦点を当てましょう:

1.座標面の回転

次のコードを使用して、新しい原点 (青い四角形の左下隅) に合わせて座標面を回転し、y 軸を反転できます。

<code class="java">g2d.translate(leftStartPlotWindow, blueTop);//translate origin to bottom-left corner of blue rectangle
g2d.scale(1, -1);//invert the y-axis</code>

2.データのプロット

スカラーを乗算して、回転した座標平面に適合するようにデータを調整します。

<code class="java">double Scalar = blueWidth/maxPlot;
ArrayList<double> scaledDiffs = new ArrayList();
for(int e = 0;e<mydiffs.size><p><strong>3. Y 軸ラベルのテキストの回転</strong></p>
<p>Y 軸でラベルを回転するには、次のコードを使用します:</p>
<pre class="brush:php;toolbar:false"><code class="java">g2d.rotate(Math.toRadians(-90), 0, 0);//rotate text 90 degrees counter-clockwise
g.drawString(yString, -(height/2)-(yStrWidth/2), yStrHeight);
g2d.rotate(Math.toRadians(+90), 0, 0);//rotate text 90 degrees clockwise</code>

完全なコード

これらの調整を加えてコードを修正すると、次の問題が解決されるはずです:

DataGUI.java

<code class="java">//... Previous code omitted for brevity
import java.awt.geom.AffineTransform;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

class DataGUI extends JFrame{
//... Previous code omitted for brevity

    @Override
    public void paint(Graphics g) {
        // ... Previous code omitted for brevity
        int height = getHeight();
        int width = getWidth();
        ins = getInsets();

        // Obtain data about graphics environment and text
        Graphics2D g2d = (Graphics2D) g;
        FontMetrics fontMetrics = g2d.getFontMetrics();
        String xString = "x-axis Label";
        int xStrWidth = fontMetrics.stringWidth(xString);
        int xStrHeight = fontMetrics.getHeight();

        // Set parameters for the inner rectangle
        int hPad = 10;
        int vPad = 6;
        int testLeftStartPlotWindow = ins.left + 5 + (3 * yStrHeight);
        int testInnerWidth = width - testLeftStartPlotWindow - ins.right - hPad;

        // Find minimum and maximum values
        getMaxMinDiffs();
        getMaxPlotVal();

        // Determine the maximum number of ticks for the axes
        double increment = 5.0;
        int numTicks = (int) (maxPlot / increment);
        int remainder = testInnerWidth % numTicks;
        int leftStartPlotWindow = testLeftStartPlotWindow - remainder;

        // Calculate the bottom padding and blue rectangle dimensions
        int bottomPad = (3 * xStrHeight) - vPad;
        int blueTop = ins.bottom + (vPad / 2) + titleStrHeight;
        int blueHeight = height - bottomPad - blueTop;
        int blueWidth = blueHeight;
        int blueBottom = blueHeight + blueTop;

        // Start drawing
        // ... Previous code omitted for brevity

        // Scale the diffs to fit the window
        double Scalar = blueWidth / maxPlot;
        List<double> scaledDiffs = new ArrayList();
        for (Double myDiff : myDiffs) {
            scaledDiffs.add(myDiff * Scalar);
        }

        // Rotate the graphics context for plotting data
        AffineTransform at = g2d.getTransform();
        g2d.translate(leftStartPlotWindow, blueTop);
        g2d.scale(1, -1);

        // Plot the scaled diffs
        for (int w = 0; w  0) {
                double prior = scaledDiffs.get(w - 1);
                int priorInt = (int) prior;
                double current = scaledDiffs.get(w);
                int currentInt = (int) current;
                g2d.drawOval(priorInt, currentInt, 4, 4);
            }
        }

        // Restore the transform for conventional rendering
        g2d.setTransform(at);
        // ... Rest of the code omitted for brevity
    }

    // ... Previous code omitted for brevity
}</double></code>

DataPanel.java

<code class="java">//... Previous code omitted for brevity

@Override
protected void paintComponent(Graphics g) {
//... Previous code omitted for brevity

int blueTop = ins.bottom+(vPad/2)+titleStrHeight;
int blueHeight = height-bottomPad-blueTop;
int blueWidth = blueHeight;
int blueBottom = blueHeight+blueTop;

//... Previous code omitted for brevity

// Rotate the graphics context for y-axis labels
g2d.rotate(Math.toRadians(-90), 0, 0);
g.drawString(yString, -(height/2)-(yStrWidth/2), yStrHeight);

// Restore the graphics context for normal rendering
g2d.rotate(Math.toRadians(+90), 0, 0);

//... Previous code omitted for brevity
}</code>

追加リソース

グラフィックス変換の詳細については、次を参照してください:

  • [Java 2D Graphics](https:// docs.oracle.com/javase/8/docs/technotes/guides/2d/index.html)

以上がデータ視覚化のために Java で座標平面と Y 軸ラベルを回転するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
JVMはオペレーティングシステムAPIの違いをどのように処理しますか?JVMはオペレーティングシステムAPIの違いをどのように処理しますか?Apr 27, 2025 am 12:18 AM

JVMは、JavanativeInterface(JNI)およびJava Standard Libraryを介してオペレーティングシステムのAPIの違いを処理します。1。JNIでは、Javaコードがローカルコードを呼び出し、オペレーティングシステムAPIと直接対話できます。 2. Java Standard Libraryは統一されたAPIを提供します。これは、異なるオペレーティングシステムAPIに内部的にマッピングされ、コードがプラットフォーム間で実行されるようにします。

Java 9で導入されたモジュール性は、プラットフォームの独立性にどのように影響しますか?Java 9で導入されたモジュール性は、プラットフォームの独立性にどのように影響しますか?Apr 27, 2025 am 12:15 AM

modularitydoesnotdirectlyectlyectjava'splatformindepensence.java'splatformendepenceismaindainededainededainededaindainedaindained bythejvm、butmodularityinfluencesApplucationStructure andmanagement、間接的なインパクチャプラット形成依存性.1)

ByteCodeとは何ですか?また、Javaのプラットフォームの独立性とどのように関係していますか?ByteCodeとは何ですか?また、Javaのプラットフォームの独立性とどのように関係していますか?Apr 27, 2025 am 12:06 AM

bytecodeinjavaisthe intermediaterepresentationthateNablesplatformindepence.1)javacodeis compiledintobytecodestoredin.classfiles.2)thejvminterpretsorcompilesthisbytecodeintomachinecodeatime、

Javaがプラットフォームに依存しない言語と見なされるのはなぜですか?Javaがプラットフォームに依存しない言語と見なされるのはなぜですか?Apr 27, 2025 am 12:03 AM

javaachievesplatformedenceTheTheTheJavavirtualMachine(JVM)、これは、javacodeisisisisisissompiledIntobytecode.2)javaCodeisisisisissompiledevedevicetecode.2)

グラフィカルユーザーインターフェイス(GUI)は、Javaのプラットフォーム独立性の課題をどのように提示できますか?グラフィカルユーザーインターフェイス(GUI)は、Javaのプラットフォーム独立性の課題をどのように提示できますか?Apr 27, 2025 am 12:02 AM

Javagui開発におけるプラットフォームの独立性は課題に直面していますが、Swing、Javafx、統一外観、パフォーマンス最適化、サードパーティライブラリ、クロスプラットフォームテストを使用することで対処できます。 Javaguiの開発は、クロスプラットフォームの一貫性を提供することを目的としたAWTとSwingに依存していますが、実際の効果はオペレーティングシステムごとに異なります。ソリューションには以下が含まれます。1)SwingおよびJavafxをGUIツールキットとして使用します。 2)uimanager.setlookandfeel()を介して外観を統合します。 3)さまざまなプラットフォームに合わせてパフォーマンスを最適化します。 4)ApachepivotやSWTなどのサードパーティライブラリを使用する。 5)一貫性を確保するために、クロスプラットフォームテストを実施します。

Java開発のどの側面がプラットフォームに依存していますか?Java開発のどの側面がプラットフォームに依存していますか?Apr 26, 2025 am 12:19 AM

javadevelopmentisnotentirelylylypratform-IndopentDuetoseveralfactors.1)jvmvariationsaffectperformanceandbehavioracrossdifferentos.2)nativeLibrariesviajniintroducePlatform-specificissues.3)giaiasystemsdifferbeTioneplateplatifflics.4)

さまざまなプラットフォームでJavaコードを実行するときにパフォーマンスの違いはありますか?なぜ?さまざまなプラットフォームでJavaコードを実行するときにパフォーマンスの違いはありますか?なぜ?Apr 26, 2025 am 12:15 AM

Javaコードは、さまざまなプラットフォームで実行するときにパフォーマンスの違いがあります。 1)JVMの実装と最適化戦略は、OracleJDKやOpenJDKなどとは異なります。 2)メモリ管理やスレッドスケジューリングなどのオペレーティングシステムの特性もパフォーマンスに影響します。 3)適切なJVMを選択し、JVMパラメーターとコード最適化を調整することにより、パフォーマンスを改善できます。

Javaのプラットフォームの独立性の制限は何ですか?Javaのプラットフォームの独立性の制限は何ですか?Apr 26, 2025 am 12:10 AM

java'splatformindepentedencehaslimitationsincludingporformanceoverhead、versioncompatibulisisues、changleSwithnativeLibraryIntegration、プラットフォーム固有の機能、およびjvminStallation/maintenation。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。