line chart candlestick chart in separate objects

This commit is contained in:
7u83 2017-10-02 23:05:29 +02:00
parent 9b33636b91
commit ce0bb75bab
13 changed files with 212 additions and 281 deletions

View File

@ -3,10 +3,45 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group> <group>
<file>file:/home/tobias/v/SeSim/src/chart/OHLCChartPainter.java</file> <file>file:/home/tube/NetBeansProjects/SeSim/src/traders/RandomTraderA.java</file>
<file>file:/home/tobias/v/SeSim/src/chart/Chart.java</file> <file>file:/home/tube/NetBeansProjects/SeSim/test/sesim/Test.java</file>
<file>file:/home/tobias/v/SeSim/src/chart/XLegendChartPainter.java</file> <file>file:/home/tube/NetBeansProjects/SeSim/src/gui/StatisticsPanel.java</file>
<file>file:/home/tobias/v/SeSim/src/chart/NewPanel.java</file> <file>file:/home/tube/NetBeansProjects/SeSim/src/gui/tools/NummericCellRenderer.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderInterface.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartTestDialog.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/ManTrader/ManTraderConsoleDialog.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderLoader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/ManTrader/ManTrader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/NewPanel.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/SeSimApplication.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/Globals.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/XLegendChartPainter.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/traders/RandomTraderB.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/OHLCChartPainter.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Logger.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/EditPreferencesDialog.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/QuotePanel.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderBase.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/Statistics.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/EditStrategies.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/MainChart.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/Chart.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Clock.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/OHLCData.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/IDGenerator.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/MinMax.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderGui.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Exchange.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/jp99.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/Locker.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/orderbook/OrderBook.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartPanal.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/sesim/OHLCDataItem.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/AboutDialog.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/Chart1.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/chart/ChartPainter.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/README.md</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/gui/TestChartdialog.java</file>
</group> </group>
</open-files> </open-files>
</project-private> </project-private>

View File

@ -1,4 +1,4 @@
#Mon, 02 Oct 2017 16:43:06 +0200 #Mon, 02 Oct 2017 22:55:32 +0200
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processors.list= annotation.processing.processors.list=

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package chart;
import java.awt.Color;
import java.awt.Graphics2D;
import sesim.OHLCDataItem;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class CandleStickChartPainter extends OHLCChartPainter {
@Override
protected void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
if (i.open < i.close) {
int xl = (int) (x + iwidth / 2);
g.setColor(Color.BLACK);
g.drawLine(xl, (int) getY(i.close), xl, (int) getY(i.high));
g.drawLine(xl, (int) getY(i.low), xl, (int) getY(i.open));
float w = iwidth;
float h = (int) (getY(i.open) - getY(i.close));
g.setColor(Color.GREEN);
g.fillRect((int) (x), (int) getY(i.close), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x), (int) getY(i.close), (int) w, (int) h);
} else {
int xl = (int) (x + iwidth / 2);
g.setColor(Color.RED);
g.drawLine(xl, (int) getY(i.high), xl, (int) getY(i.close));
g.drawLine(xl, (int) getY(i.open), xl, (int) getY(i.low));
float w = iwidth;
float h = (int) (getY(i.close) - getY(i.open));
g.fillRect((int) (x), (int) getY(i.open), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x), (int) getY(i.open), (int) w, (int) h);
}
}
}

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="498" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="341" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View File

@ -1,170 +0,0 @@
package chart;
import gui.Globals;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;
import javax.swing.JScrollBar;
import javax.swing.JViewport;
import javax.swing.Scrollable;
import sesim.Exchange.QuoteReceiver;
import sesim.OHLCData;
import sesim.OHLCDataItem;
import sesim.Quote;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class Chart1 extends javax.swing.JPanel implements QuoteReceiver, AdjustmentListener {
public JScrollBar xbar;
/**
* Creates new form Chart1
*/
public Chart1() {
initComponents();
System.out.printf("Now cursor\n");
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
if (Globals.se == null) {
return;
}
setSize(new Dimension(9000, 500));
Globals.se.addQuoteReceiver(this);
}
ArrayList <ChartPainter> chartPainters = new ArrayList<>();
/**
*
* @param p
*/
public void addChartPainter(ChartPainter p){
chartPainters.add(p);
}
private void drawChart(Graphics2D g) {
JViewport vp = new JViewport();
// if (Globals.se==null)
// return;
Dimension d = new Dimension(200, 200);
setPreferredSize(d);
g.setClip(10, 10, 800, 200);
g.setColor(Color.red);
g.drawLine(0, 0, 8000, 610);
if (Globals.se == null) {
return;
}
revalidate();
System.out.printf("Setting pref size\n");
OHLCData data = Globals.se.getOHLCdata(60000);
/*
int first_bar = 0;
int last_bar = data.size();
OHLCDataItem prev = null;
for (int i = first_bar; i < last_bar; i++) {
OHLCDataItem di = data.get(i);
int x_unit_width = 1;
int x = (int) (i * em_width * x_unit_width);
g.setColor(Color.red);
g.drawLine(x, 0, x, 10);
//em_width;
//this.drawItem(ctx, (int) (x - em_width * x_unit_width), x, prev, di); //, ctx.scaling, data.getMin());
// myi++;
prev = di;
}
*/
}
OHLCData data;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (Globals.se==null)
return;
//this.xbar.setMaximum(994000);
XLegendChartPainter p = new XLegendChartPainter();
data = Globals.se.getOHLCdata(60000*60);
ChartDef def = new ChartDef();
def.x_unit_width = 1.0;
def.x_scrollbar=xbar;
for (ChartPainter painter: chartPainters){
painter.drawChart((Graphics2D)g, xbar, data, this, def);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 498, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 341, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
public void UpdateQuote(Quote q) {
int s = data.size();
System.out.printf("Data size %d",s);
// xbar.setMaximum(data.size());
repaint();
}
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.printf("Adjustemntlistener called %d\n", xbar.getValue());
this.repaint();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@ -37,7 +37,7 @@ public class ChartDef {
/** /**
* width of an x unit in em * width of an x unit in em
*/ */
double x_unit_width=1.0; double x_unit_width=4.0;
ChartDef(){ ChartDef(){

View File

@ -1,7 +1,7 @@
package chart; package chart;
import gui.Globals; import gui.Globals;
import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
@ -108,14 +108,13 @@ public class ChartPanel extends javax.swing.JPanel implements QuoteReceiver, Adj
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
int s = data.size(); int s = data.size();
System.out.printf("Data size %d",s); // System.out.printf("Data size %d",s);
// xbar.setMaximum(data.size()); // xbar.setMaximum(data.size());
repaint(); repaint();
} }
@Override @Override
public void adjustmentValueChanged(AdjustmentEvent e) { public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.printf("Adjustemntlistener called %d\n", xbar.getValue());
this.repaint(); this.repaint();
} }

View File

@ -59,7 +59,7 @@
<Property name="name" type="java.lang.String" value="" noResource="true"/> <Property name="name" type="java.lang.String" value="" noResource="true"/>
</Properties> </Properties>
</Component> </Component>
<Container class="chart.Chart1" name="chart12"> <Container class="chart.ChartPanel" name="chart12">
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
@ -74,7 +74,7 @@
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
</Container> </Container>
<Container class="chart.Chart1" name="chart11"> <Container class="chart.ChartPanel" name="chart11">
<Properties> <Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo"> <Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">

View File

@ -34,7 +34,7 @@ import sesim.Quote;
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class ChartTestDialog extends javax.swing.JDialog implements QuoteReceiver{ public class ChartTestDialog extends javax.swing.JDialog implements QuoteReceiver {
/** /**
* Creates new form ChartTestDialog * Creates new form ChartTestDialog
@ -43,21 +43,23 @@ public class ChartTestDialog extends javax.swing.JDialog implements QuoteReceive
super(parent, modal); super(parent, modal);
initComponents(); initComponents();
setLocationRelativeTo(parent); setLocationRelativeTo(parent);
this.chart12.xbar=this.jScrollBar1; this.chart12.xbar = this.jScrollBar1;
this.jScrollBar1.addAdjustmentListener(chart12); this.jScrollBar1.addAdjustmentListener(chart12);
ChartPainter p = new XLegendChartPainter(); ChartPainter p = new XLegendChartPainter();
chart12.addChartPainter(p); chart12.addChartPainter(p);
Globals.se.addQuoteReceiver(this); Globals.se.addQuoteReceiver(this);
this.chart11.xbar=this.jScrollBar1; this.chart11.xbar = this.jScrollBar1;
this.jScrollBar1.addAdjustmentListener(chart11); this.jScrollBar1.addAdjustmentListener(chart11);
p = new OHLCChartPainter();
p = new CandleStickChartPainter();
this.chart11.addChartPainter(p); this.chart11.addChartPainter(p);
p = new LineChartPainter();
this.chart11.addChartPainter(p);
} }
/** /**
@ -70,8 +72,8 @@ public class ChartTestDialog extends javax.swing.JDialog implements QuoteReceive
private void initComponents() { private void initComponents() {
jScrollBar1 = new javax.swing.JScrollBar(); jScrollBar1 = new javax.swing.JScrollBar();
chart12 = new chart.Chart1(); chart12 = new chart.ChartPanel();
chart11 = new chart.Chart1(); chart11 = new chart.ChartPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMaximumSize(new java.awt.Dimension(800, 600)); setMaximumSize(new java.awt.Dimension(800, 600));
@ -175,14 +177,14 @@ public class ChartTestDialog extends javax.swing.JDialog implements QuoteReceive
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private chart.Chart1 chart11; private chart.ChartPanel chart11;
private chart.Chart1 chart12; private chart.ChartPanel chart12;
private javax.swing.JScrollBar jScrollBar1; private javax.swing.JScrollBar jScrollBar1;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@Override @Override
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
OHLCData data = Globals.se.getOHLCdata(60000*60*4); OHLCData data = Globals.se.getOHLCdata(60000 * 60 * 4);
this.jScrollBar1.setMaximum(data.size()); this.jScrollBar1.setMaximum(data.size());
repaint(); repaint();
System.out.printf("SETMAXIMUM: %d", data.size()); System.out.printf("SETMAXIMUM: %d", data.size());

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2017, 7u83 <7u83@mail.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package chart;
import java.awt.Color;
import java.awt.Graphics2D;
import sesim.OHLCDataItem;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class LineChartPainter extends OHLCChartPainter{
@Override
void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) {
if (prev == null) {
prev = i;
}
int y1 = (int) getY(prev.close);
int y2 = (int) getY(i.close);
Color cur = g.getColor();
g.setColor(Color.RED);
g.drawLine(prevx, y1, x, y2);
g.setColor(cur);
}
}

View File

@ -39,92 +39,60 @@ import static sun.awt.geom.Curve.prev;
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class OHLCChartPainter extends ChartPainter { public abstract class OHLCChartPainter extends ChartPainter {
private float iwidth; protected float iwidth;
private MinMax mm; private MinMax mm;
private Dimension dim; private Dimension dim;
private float y_scaling; private float y_scaling;
float getY(float y) { float getY(float y) {
//c_yscaling = ctx.rect.height / c_mm.getDiff(); //c_yscaling = ctx.rect.height / c_mm.getDiff();
// float ys = dim.height / mm.getDiff(); // float ys = dim.height / mm.getDiff();
if (mm.isLog()) { if (mm.isLog()) {
// return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys; // return rect.height + rect.y - ((float) Math.log(y) - c_mm.getMin()) * ys;
} }
return (dim.height - ((y - mm.getMin()) * y_scaling)) ; return (dim.height - ((y - mm.getMin()) * y_scaling));
} }
private void drawCandleItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) { abstract void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i);
if (i.open < i.close) {
int xl = (int) (x + iwidth / 2);
g.setColor(Color.BLACK);
g.drawLine(xl, (int) getY(i.close), xl, (int) getY(i.high));
g.drawLine(xl, (int) getY(i.low), xl, (int) getY(i.open));
float w = iwidth;
float h = (int) (getY(i.open) - getY(i.close));
g.setColor(Color.GREEN);
g.fillRect((int) (x), (int) getY(i.close), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x), (int) getY(i.close), (int) w, (int) h);
} else {
int xl = (int) (x + iwidth / 2);
g.setColor(Color.RED);
g.drawLine(xl, (int) getY(i.high), xl, (int) getY(i.close));
g.drawLine(xl, (int) getY(i.open), xl, (int) getY(i.low));
float w = iwidth;
float h = (int) (getY(i.close) - getY(i.open));
g.fillRect((int) (x), (int) getY(i.open), (int) w, (int) h);
g.setColor(Color.BLACK);
g.drawRect((int) (x), (int) getY(i.open), (int) w, (int) h);
}
}
@Override @Override
public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, JPanel p, ChartDef def) { public void drawChart(Graphics2D g, JScrollBar sb, OHLCData data, JPanel p, ChartDef def) {
init(g); init(g);
iwidth = (float) ((def.x_unit_width * em_width) * 0.9f); iwidth = (float) ((def.x_unit_width * em_width) * 0.9f);
int first_bar = def.x_scrollbar.getValue(); int first_bar = def.x_scrollbar.getValue();
dim = p.getSize(); dim = p.getSize();
int bars = (int) (dim.width / (def.x_unit_width * em_width)); int bars = (int) (dim.width / (def.x_unit_width * em_width));
int last_bar = first_bar+bars; int last_bar = first_bar + bars+1;
mm = data.getMinMax(first_bar, first_bar+bars); mm = data.getMinMax(first_bar, last_bar);
y_scaling = dim.height / mm.getDiff(); y_scaling = dim.height / mm.getDiff();
OHLCDataItem prevd=null; OHLCDataItem prevd = null;
int prevx; int prevx;
if (data.size()>0 && first_bar<data.size()){ if (data.size() > 0 && first_bar < data.size()) {
prevd = data.get(first_bar); prevd = data.get(first_bar);
} }
for (int b = first_bar,n=0; b < last_bar && b<data.size(); b++,n++) { prevd=null;
for (int b = first_bar, n = 0; b < last_bar && b < data.size(); b++, n++) {
OHLCDataItem d = data.get(b); OHLCDataItem d = data.get(b);
int x = (int) (n * em_width * def.x_unit_width); //em_width; int x = (int) (n * em_width * def.x_unit_width); //em_width;
this.drawCandleItem(g, (int) (x - em_width * def.x_unit_width), x, prevd, d); drawItem(g, (int) (x - em_width * def.x_unit_width), x, prevd, d);
prevd = d;
//this.drawCandleItem(g, (int)((n-1)*def.x_unit_width*em_width), (int)(n*def.x_unit_width*em_width), prevd, d); //this.drawCandleItem(g, (int)((n-1)*def.x_unit_width*em_width), (int)(n*def.x_unit_width*em_width), prevd, d);
} }
} }

View File

@ -38,7 +38,7 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents> <SubComponents>
<Container class="chart.Chart1" name="chart11"> <Container class="chart.ChartPanel" name="chart11">
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
@ -56,4 +56,4 @@
</SubComponents> </SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -28,7 +28,7 @@ public class jp99 extends javax.swing.JPanel {
private void initComponents() { private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
chart11 = new chart.Chart1(); chart11 = new chart.ChartPanel();
javax.swing.GroupLayout chart11Layout = new javax.swing.GroupLayout(chart11); javax.swing.GroupLayout chart11Layout = new javax.swing.GroupLayout(chart11);
chart11.setLayout(chart11Layout); chart11.setLayout(chart11Layout);
@ -63,7 +63,7 @@ public class jp99 extends javax.swing.JPanel {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private chart.Chart1 chart11; private chart.ChartPanel chart11;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }